• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegraphics API Reference
  • KDE Home
  • Contact Us
 

okular

  • sources
  • kde-4.12
  • kdegraphics
  • okular
  • core
  • script
kjs_util.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2008 by Pino Toscano <pino@kde.org> *
3  * Copyright (C) 2008 by Harri Porten <porten@kde.org> *
4  * *
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  ***************************************************************************/
10 
11 #include "kjs_util_p.h"
12 
13 #include <kjs/kjsobject.h>
14 #include <kjs/kjsprototype.h>
15 #include <kjs/kjsarguments.h>
16 
17 #include <kurl.h>
18 
19 using namespace Okular;
20 
21 static KJSPrototype *g_utilProto;
22 
23 static KJSObject crackURL( KJSContext *context, void *,
24  const KJSArguments &arguments )
25 {
26  if ( arguments.count() < 1 )
27  {
28  return context->throwException( "Missing URL argument" );
29  }
30  QString cURL = arguments.at( 0 ).toString( context );
31  KUrl url( cURL );
32  if ( !url.isValid() )
33  {
34  return context->throwException( "Invalid URL" );
35  }
36  if ( url.protocol() != QLatin1String( "file" )
37  || url.protocol() != QLatin1String( "http" )
38  || url.protocol() != QLatin1String( "https" ) )
39  {
40  return context->throwException( "Protocol not valid: '" + url.protocol() + '\'' );
41  }
42 
43  KJSObject obj;
44  obj.setProperty( context, "cScheme", url.protocol() );
45  if ( url.hasUser() )
46  obj.setProperty( context, "cUser", url.user() );
47  if ( url.hasPass() )
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.
53  if ( url.hasRef() )
54  obj.setProperty( context, "cFragments", url.ref() );
55 
56  return obj;
57 }
58 
59 void JSUtil::initType( KJSContext *ctx )
60 {
61  static bool initialized = false;
62  if ( initialized )
63  return;
64  initialized = true;
65 
66  g_utilProto = new KJSPrototype();
67  g_utilProto->defineFunction( ctx, "crackURL", crackURL );
68 }
69 
70 KJSObject JSUtil::object( KJSContext *ctx )
71 {
72  return g_utilProto->constructObject( ctx, 0 );
73 }
74 
g_utilProto
static KJSPrototype * g_utilProto
Definition: kjs_util.cpp:21
Okular::JSUtil::object
static KJSObject object(KJSContext *ctx)
Definition: kjs_util.cpp:70
crackURL
static KJSObject crackURL(KJSContext *context, void *, const KJSArguments &arguments)
Definition: kjs_util.cpp:23
kjs_util_p.h
Okular::JSUtil::initType
static void initType(KJSContext *ctx)
Definition: kjs_util.cpp:59
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:45:02 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okular

Skip menu "okular"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegraphics API Reference

Skip menu "kdegraphics API Reference"
  •     libkdcraw
  •     libkexiv2
  •     libkipi
  •     libksane
  • okular

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal