kjsembed
qformbuilder_binding.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2005, 2006 Ian Reinhart Geiser <geiseri@kde.org> 00003 Copyright (C) 2005, 2006 Matt Broadstone <mbroadst@gmail.com> 00004 Copyright (C) 2005, 2006 Richard J. Moore <rich@kde.org> 00005 Copyright (C) 2005, 2006 Erik L. Bunce <kde@bunce.us> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00022 #include "qformbuilder_binding.h" 00023 00024 #include <QtGui/QWidget> 00025 #include <QtDesigner/QFormBuilder> 00026 #include <QtCore/QFile> 00027 #include <QtCore/QDebug> 00028 00029 #include <kjs/object.h> 00030 00031 #include "static_binding.h" 00032 #include "qwidget_binding.h" 00033 #include "kjseglobal.h" 00034 00035 using namespace KJSEmbed; 00036 NO_METHODS( FormBuilder ) 00037 NO_ENUMS( FormBuilder ) 00038 NO_STATICS( FormBuilder ) 00039 00040 START_CTOR( FormBuilder, Form, 2 ) 00041 if( args.size() > 0 ) 00042 { 00043 QFormBuilder *formBuilder = new QFormBuilder(); 00044 QWidget *parentWidget = 0; 00045 KJSEmbed::QObjectBinding *parentImp = KJSEmbed::extractBindingImp<KJSEmbed::QObjectBinding>(exec, args[1] ); 00046 if( parentImp ) 00047 { 00048 parentWidget = parentImp->object<QWidget>(); 00049 } 00050 QString fileName = toQString(args[0]->toString(exec)); 00051 QFile uiFile(fileName); 00052 if( uiFile.open(QIODevice::ReadOnly | QIODevice::Text) ) 00053 { 00054 QWidget *returnWidget = formBuilder->load(&uiFile,parentWidget); 00055 uiFile.close(); 00056 if( returnWidget == 0 ) 00057 { 00058 delete formBuilder; 00059 return KJS::throwError(exec, KJS::GeneralError, i18n("There was an error reading the file '%1'", 00060 fileName)); 00061 } 00062 KJS::JSObject *form = new QWidgetBinding( exec, returnWidget ); 00063 delete formBuilder; 00064 return form; 00065 } 00066 delete formBuilder; 00067 return KJS::throwError(exec, KJS::GeneralError, i18n("Could not read file '%1'", 00068 fileName)); 00069 } 00070 return KJS::throwError(exec, KJS::GeneralError, i18n("Must supply a filename.")); 00071 END_CTOR 00072 00073 //kate: indent-spaces on; indent-width 4; replace-tabs on; indent-mode cstyle;
KDE 4.6 API Reference