Okular

kjs_data.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Pino Toscano <[email protected]>
3  SPDX-FileCopyrightText: 2008 Harri Porten <[email protected]>
4 
5  SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #include "kjs_data_p.h"
9 
10 #include <kjs/kjsobject.h>
11 #include <kjs/kjsprototype.h>
12 
13 #include <QDateTime>
14 
15 #include "../document.h"
16 
17 using namespace Okular;
18 
19 static KJSPrototype *g_dataProto;
20 
21 static KJSObject dataGetCreationDate(KJSContext *ctx, void *object)
22 {
23  const EmbeddedFile *file = reinterpret_cast<EmbeddedFile *>(object);
24 
25  return KJSDate(ctx, file->creationDate());
26 }
27 
28 static KJSObject dataGetDescription(KJSContext *, void *object)
29 {
30  const EmbeddedFile *file = reinterpret_cast<EmbeddedFile *>(object);
31 
32  return KJSString(file->description());
33 }
34 
35 static KJSObject dataGetMIMEType(KJSContext *, void *)
36 {
37  return KJSString("");
38 }
39 
40 static KJSObject dataGetModDate(KJSContext *ctx, void *object)
41 {
42  const EmbeddedFile *file = reinterpret_cast<EmbeddedFile *>(object);
43 
44  return KJSDate(ctx, file->modificationDate());
45 }
46 
47 static KJSObject dataGetName(KJSContext *, void *object)
48 {
49  const EmbeddedFile *file = reinterpret_cast<EmbeddedFile *>(object);
50 
51  return KJSString(file->name());
52 }
53 
54 static KJSObject dataGetPath(KJSContext *, void *)
55 {
56  return KJSString("");
57 }
58 
59 static KJSObject dataGetSize(KJSContext *, void *object)
60 {
61  const EmbeddedFile *file = reinterpret_cast<EmbeddedFile *>(object);
62  return KJSNumber(file->size());
63 }
64 
65 void JSData::initType(KJSContext *ctx)
66 {
67  static bool initialized = false;
68  if (initialized) {
69  return;
70  }
71  initialized = true;
72 
73  if (!g_dataProto) {
74  g_dataProto = new KJSPrototype();
75  }
76 
77  g_dataProto->defineProperty(ctx, QStringLiteral("creationDate"), dataGetCreationDate);
78  g_dataProto->defineProperty(ctx, QStringLiteral("description"), dataGetDescription);
79  g_dataProto->defineProperty(ctx, QStringLiteral("MIMEType"), dataGetMIMEType);
80  g_dataProto->defineProperty(ctx, QStringLiteral("modDate"), dataGetModDate);
81  g_dataProto->defineProperty(ctx, QStringLiteral("name"), dataGetName);
82  g_dataProto->defineProperty(ctx, QStringLiteral("path"), dataGetPath);
83  g_dataProto->defineProperty(ctx, QStringLiteral("size"), dataGetSize);
84 }
85 
86 KJSObject JSData::wrapFile(KJSContext *ctx, EmbeddedFile *f)
87 {
88  return g_dataProto->constructObject(ctx, f);
89 }
virtual int size() const =0
Returns the size (in bytes) of the file, if available, or -1 otherwise.
The documentation to the global Okular namespace.
Definition: action.h:16
virtual QString name() const =0
Returns the name of the file.
virtual QDateTime modificationDate() const =0
Returns the modification date of the file, or an invalid date if not available.
virtual QDateTime creationDate() const =0
Returns the creation date of the file, or an invalid date if not available.
void defineProperty(KJSContext *ctx, const QString &name, PropertyGetter getter, PropertySetter setter=nullptr)
KJSObject constructObject(KJSContext *ctx, void *internalValue=nullptr)
virtual QString description() const =0
Returns the description of the file, or an empty string if not available.
An embedded file into the document.
Definition: document.h:1456
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Mar 23 2023 04:04:24 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.