File indexing completed on 2024-05-26 11:45:01

0001 /* This file is part of the KDE libraries
0002     Copyright (C) 2005, 2006 Ian Reinhart Geiser <geiseri@kde.org>
0003     Copyright (C) 2005, 2006 Matt Broadstone <mbroadst@gmail.com>
0004     Copyright (C) 2005, 2006 Richard J. Moore <rich@kde.org>
0005     Copyright (C) 2005, 2006 Erik L. Bunce <kde@bunce.us>
0006 
0007     This library is free software; you can redistribute it and/or
0008     modify it under the terms of the GNU Library General Public
0009     License as published by the Free Software Foundation; either
0010     version 2 of the License, or (at your option) any later version.
0011 
0012     This library is distributed in the hope that it will be useful,
0013     but WITHOUT ANY WARRANTY; without even the implied warranty of
0014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015     Library General Public License for more details.
0016 
0017     You should have received a copy of the GNU Library General Public License
0018     along with this library; see the file COPYING.LIB.  If not, write to
0019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020     Boston, MA 02110-1301, USA.
0021 */
0022 #include "settings.h"
0023 #include <QSettings>
0024 #include "kjseglobal.h"
0025 
0026 using namespace KJSEmbed;
0027 
0028 START_QOBJECT_METHOD(callAllKeys, QSettings)
0029 QStringList keys = object->allKeys();
0030 result = KJSEmbed::convertToValue(exec, keys);
0031 END_QOBJECT_METHOD
0032 
0033 START_QOBJECT_METHOD(callSetValue, QSettings)
0034 QString key = KJSEmbed::extractQString(exec, args, 0);
0035 QVariant value = KJSEmbed::convertToVariant(exec, args[1]);
0036 object->setValue(key, value);
0037 END_QOBJECT_METHOD
0038 
0039 START_QOBJECT_METHOD(callValue, QSettings)
0040 QVariant value;
0041 QString key = KJSEmbed::extractQString(exec, args, 0);
0042 if (args.size() == 2)
0043 {
0044     value = KJSEmbed::convertToVariant(exec, args[1]);
0045 }
0046 value = object->value(key, value);
0047 result = KJSEmbed::convertToValue(exec, value);
0048 END_QOBJECT_METHOD
0049 
0050 START_QOBJECT_METHOD(callClear, QSettings)
0051 object->clear();
0052 END_QOBJECT_METHOD
0053 
0054 START_QOBJECT_METHOD(callSync, QSettings)
0055 object->sync();
0056 END_QOBJECT_METHOD
0057 
0058 START_QOBJECT_METHOD(callRemove, QSettings)
0059 QString key = KJSEmbed::extractQString(exec, args, 0);
0060 object->remove(key);
0061 END_QOBJECT_METHOD
0062 
0063 START_STATIC_OBJECT_METHOD(callSetPath)
0064 // QSettings::Format format = (QSettings::Format) KJSEmbed::extractVariant<uint>(exec, args, 0);
0065 // QSettings::Scope scope = (QSettings::Scope) KJSEmbed::extractVariant<uint>(exec, args, 1);
0066 QString path = KJSEmbed::extractQString(exec, args, 2);
0067 //QSettings::setSystemIniPath(format,scope,path);
0068 return KJS::jsNull();
0069 END_STATIC_OBJECT_METHOD
0070 
0071 START_METHOD_LUT(SettingsBinding)
0072 {"allKeys", 0, KJS::DontDelete | KJS::ReadOnly, &callAllKeys },
0073 {"setValue", 2, KJS::DontDelete | KJS::ReadOnly, &callSetValue },
0074 {"value", 1, KJS::DontDelete | KJS::ReadOnly, &callValue },
0075 {"clear", 0, KJS::DontDelete | KJS::ReadOnly, &callClear },
0076 {"sync", 0, KJS::DontDelete | KJS::ReadOnly, &callSync },
0077 {"remove", 1, KJS::DontDelete | KJS::ReadOnly, &callRemove }
0078 END_METHOD_LUT
0079 
0080 START_ENUM_LUT(SettingsBinding)
0081 {"NativeFormat", QSettings::NativeFormat},
0082 {"IniFormat", QSettings::IniFormat},
0083 //{"InvalidFormat", QSettings::InvalidFormat},
0084 {"UserScope", QSettings::UserScope},
0085 {"SystemScope", QSettings::SystemScope}
0086 END_ENUM_LUT
0087 
0088 START_STATIC_METHOD_LUT(SettingsBinding)
0089 {"setPath", 3, KJS::DontDelete | KJS::ReadOnly, &callSetPath
0090 }
0091 END_METHOD_LUT
0092 
0093 KJSO_SIMPLE_BINDING_CTOR(SettingsBinding, QSettings, QObjectBinding)
0094 KJSO_QOBJECT_BIND(SettingsBinding, QSettings)
0095 
0096 KJSO_START_CTOR(SettingsBinding, QSettings, 1)
0097 QSettings *settings = nullptr;
0098 if (args.size() == 1)
0099 {
0100     QObject *parent = KJSEmbed::extractObject<QObject>(exec, args, 0);
0101     settings = new QSettings(parent);
0102 } else if (args.size() == 3)
0103 {
0104     QString fileName = KJSEmbed::extractQString(exec, args, 0);
0105     QSettings::Format format = (QSettings::Format) KJSEmbed::extractVariant<uint>(exec, args, 1);
0106     QObject *parent = KJSEmbed::extractObject<QObject>(exec, args, 2);
0107     settings = new QSettings(fileName, format, parent);
0108 } else if (args.size() == 4)
0109 {
0110     QSettings::Scope scope = (QSettings::Scope) KJSEmbed::extractVariant<uint>(exec, args, 0);
0111     QString organization = KJSEmbed::extractQString(exec, args, 1);
0112     QString application = KJSEmbed::extractQString(exec, args, 2);
0113     QObject *parent = KJSEmbed::extractObject<QObject>(exec, args, 3);
0114     settings = new QSettings(scope, organization, application, parent);
0115 } else
0116 {
0117     settings = new QSettings();
0118 }
0119 
0120 return new SettingsBinding(exec, settings);
0121 KJSO_END_CTOR
0122