Warning, file /frameworks/kjsembed/src/kjsembed/qformbuilder_binding.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 "qformbuilder_binding.h" 0023 0024 #include <QWidget> 0025 #include <QtDesigner/QFormBuilder> 0026 #include <QFile> 0027 #include <QDebug> 0028 0029 #include <kjs/object.h> 0030 0031 #include "static_binding.h" 0032 #include "qwidget_binding.h" 0033 #include "kjseglobal.h" 0034 0035 using namespace KJSEmbed; 0036 NO_METHODS(FormBuilder) 0037 NO_ENUMS(FormBuilder) 0038 NO_STATICS(FormBuilder) 0039 0040 START_CTOR(FormBuilder, Form, 2) 0041 if (args.size() > 0) 0042 { 0043 QFormBuilder *formBuilder = new QFormBuilder(); 0044 QWidget *parentWidget = 0; 0045 KJSEmbed::QObjectBinding *parentImp = KJSEmbed::extractBindingImp<KJSEmbed::QObjectBinding>(exec, args[1]); 0046 if (parentImp) { 0047 parentWidget = parentImp->object<QWidget>(); 0048 } 0049 QString fileName = toQString(args[0]->toString(exec)); 0050 QFile uiFile(fileName); 0051 if (uiFile.open(QIODevice::ReadOnly | QIODevice::Text)) { 0052 QWidget *returnWidget = formBuilder->load(&uiFile, parentWidget); 0053 uiFile.close(); 0054 if (returnWidget == 0) { 0055 delete formBuilder; 0056 return KJS::throwError(exec, KJS::GeneralError, i18n("There was an error reading the file '%1'", 0057 fileName)); 0058 } 0059 KJS::JSObject *form = new QWidgetBinding(exec, returnWidget); 0060 delete formBuilder; 0061 return form; 0062 } 0063 delete formBuilder; 0064 return KJS::throwError(exec, KJS::GeneralError, i18n("Could not read file '%1'", 0065 fileName)); 0066 } 0067 return KJS::throwError(exec, KJS::GeneralError, i18n("Must supply a filename.")); 0068 END_CTOR 0069