File indexing completed on 2024-12-08 12:23:08

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 "qaction_binding.h"
0023 #include "static_binding.h"
0024 #include "kjseglobal.h"
0025 
0026 #include <kjs/object.h>
0027 #include <QDebug>
0028 
0029 #include <QtUiTools/QUiLoader>
0030 
0031 namespace KJSEmbed
0032 {
0033 QUiLoader *uiLoader();
0034 }
0035 
0036 using namespace KJSEmbed;
0037 
0038 NO_METHODS(Action)
0039 NO_ENUMS(Action)
0040 NO_STATICS(Action)
0041 
0042 KJSO_SIMPLE_BINDING_CTOR(Action, QAction, QObjectBinding)
0043 KJSO_QOBJECT_BIND(Action, QAction)
0044 
0045 KJSO_START_CTOR(Action, QAction, 0)
0046 QObject *parent = KJSEmbed::extractObject<QObject>(exec, args, 0, nullptr);
0047 QString actionName = KJSEmbed::extractQString(exec, args, 1);
0048 
0049 QAction *action = uiLoader()->createAction(parent, actionName);
0050 if (action)
0051 {
0052     KJS::JSObject *actionObject = new Action(exec, action);
0053     return actionObject;
0054 } else
0055 {
0056     return KJS::throwError(exec, KJS::GeneralError, i18n("Action takes 2 args."));
0057 }
0058 KJSO_END_CTOR
0059 
0060 NO_METHODS(ActionGroup)
0061 NO_ENUMS(ActionGroup)
0062 NO_STATICS(ActionGroup)
0063 
0064 KJSO_SIMPLE_BINDING_CTOR(ActionGroup, QActionGroup, QObjectBinding)
0065 KJSO_QOBJECT_BIND(ActionGroup, QActionGroup)
0066 
0067 KJSO_START_CTOR(ActionGroup, QActionGroup, 0)
0068 if (args.size() == 2)
0069 {
0070     QObject *parent = KJSEmbed::extractObject<QObject>(exec, args, 0, nullptr);
0071     QString actionName = KJSEmbed::extractQString(exec, args, 1);
0072 
0073     QActionGroup *action = uiLoader()->createActionGroup(parent, actionName);
0074     if (action) {
0075         KJS::JSObject *actionObject = new ActionGroup(exec, action);
0076         return actionObject;
0077     } else {
0078         return KJS::throwError(exec, KJS::GeneralError, i18n("ActionGroup takes 2 args."));
0079         // return KJSEmbed::throwError(exec, i18n("ActionGroup takes 2 args."));
0080     }
0081 }
0082 // Trow error incorrect args
0083 return KJS::throwError(exec, KJS::GeneralError, i18n("Must supply a valid parent."));
0084 // return KJSEmbed::throwError(exec, i18n("Must supply a valid parent."));
0085 END_CTOR
0086