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_data_p.h"
13 #include <kjs/kjsobject.h>
14 #include <kjs/kjsprototype.h>
16 #include <qdatetime.h>
18 #include "../document.h"
20 using namespace Okular
;
22 static KJSPrototype
*g_dataProto
;
24 static KJSObject
dataGetCreationDate( KJSContext
*ctx
, void *object
)
26 const EmbeddedFile
*file
= reinterpret_cast< EmbeddedFile
* >( object
);
28 return KJSDate( ctx
, file
->creationDate() );
31 static KJSObject
dataGetDescription( KJSContext
*, void *object
)
33 const EmbeddedFile
*file
= reinterpret_cast< EmbeddedFile
* >( object
);
35 return KJSString( file
->description() );
38 static KJSObject
dataGetMIMEType( KJSContext
*, void *object
)
40 return KJSString( "" );
43 static KJSObject
dataGetModDate( KJSContext
*ctx
, void *object
)
45 const EmbeddedFile
*file
= reinterpret_cast< EmbeddedFile
* >( object
);
47 return KJSDate( ctx
, file
->modificationDate() );
50 static KJSObject
dataGetName( KJSContext
*, void *object
)
52 const EmbeddedFile
*file
= reinterpret_cast< EmbeddedFile
* >( object
);
54 return KJSString( file
->name() );
57 static KJSObject
dataGetPath( KJSContext
*, void *object
)
59 return KJSString( "" );
62 static KJSObject
dataGetSize( KJSContext
*, void *object
)
64 const EmbeddedFile
*file
= reinterpret_cast< EmbeddedFile
* >( object
);
65 return KJSNumber( file
->size() );
68 void JSData::initType( KJSContext
*ctx
)
70 static bool initialized
= false;
76 g_dataProto
= new KJSPrototype();
78 g_dataProto
->defineProperty( ctx
, "creationDate", dataGetCreationDate
);
79 g_dataProto
->defineProperty( ctx
, "description", dataGetDescription
);
80 g_dataProto
->defineProperty( ctx
, "MIMEType", dataGetMIMEType
);
81 g_dataProto
->defineProperty( ctx
, "modDate", dataGetModDate
);
82 g_dataProto
->defineProperty( ctx
, "name", dataGetName
);
83 g_dataProto
->defineProperty( ctx
, "path", dataGetPath
);
84 g_dataProto
->defineProperty( ctx
, "size", dataGetSize
);
87 KJSObject
JSData::wrapFile( KJSContext
*ctx
, EmbeddedFile
*f
)
89 return g_dataProto
->constructObject( ctx
, f
);