File indexing completed on 2024-11-10 09:42:22

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 "url.h"
0023 
0024 #include <QDebug>
0025 #include <QUrl>
0026 
0027 using namespace KJSEmbed;
0028 
0029 const KJS::ClassInfo UrlBinding::info = { "QUrl", &VariantBinding::info, nullptr, nullptr };
0030 UrlBinding::UrlBinding(KJS::ExecState *exec, const QUrl &value)
0031     : VariantBinding(exec, value)
0032 {
0033     StaticBinding::publish(exec, this, VariantFactory::methods());
0034     StaticBinding::publish(exec, this, Url::methods());
0035 }
0036 
0037 namespace UrlNS
0038 {
0039 
0040 START_VARIANT_METHOD(callisValid, QUrl)
0041 bool cppValue = value.isValid();
0042 result = KJS::jsBoolean(cppValue);
0043 END_VARIANT_METHOD
0044 
0045 START_VARIANT_METHOD(toString, QUrl)
0046 QUrl::FormattingOptions opts = (QUrl::FormattingOptions)KJSEmbed::extractInt(exec, args, 0, QUrl::None);
0047 result = KJS::jsString(value.toString(opts));
0048 END_VARIANT_METHOD
0049 }
0050 
0051 START_METHOD_LUT(Url)
0052 {"toString", 0, KJS::DontDelete | KJS::ReadOnly, &UrlNS::toString},
0053 {"isValid", 0, KJS::DontDelete | KJS::ReadOnly, &UrlNS::callisValid}
0054 END_METHOD_LUT
0055 
0056 START_ENUM_LUT(Url)
0057 {"None", QUrl::None},
0058 {"RemoveScheme", QUrl::RemoveScheme},
0059 {"RemovePassword", QUrl::RemovePassword},
0060 {"RemoveUserInfo", QUrl::RemoveUserInfo},
0061 {"RemovePort", QUrl::RemovePort},
0062 {"RemoveAuthority", QUrl::RemoveAuthority},
0063 {"RemovePath", QUrl::RemovePath},
0064 {"RemoveQuery", QUrl::RemoveQuery},
0065 {"RemoveFragment", QUrl::RemoveFragment},
0066 {"StripTrailingSlash", QUrl::StripTrailingSlash}
0067 END_ENUM_LUT
0068 
0069 NO_STATICS(Url)
0070 
0071 START_CTOR(Url, QUrl, 0)
0072 if (args.size() == 1)
0073 {
0074     return new KJSEmbed::UrlBinding(exec, QUrl(KJSEmbed::extractQString(exec, args, 0)));
0075 }
0076 
0077 return new KJSEmbed::UrlBinding(exec, QUrl());
0078 END_CTOR
0079