• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

kjsembed

quiloader_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 "quiloader_binding.h"
00023 
00024 #include <QtGui/QWidget>
00025 #include <QtCore/QFile>
00026 #include <QtCore/QDebug>
00027 
00028 #include "qwidget_binding.h"
00029 #include "qobject_binding.h"
00030 #include "qaction_binding.h"
00031 #include "qlayout_binding.h"
00032 #include "static_binding.h"
00033 #include "kjseglobal.h"
00034 
00035 using namespace KJSEmbed;
00036 
00037 KJSO_SIMPLE_BINDING_CTOR( UiLoaderBinding, QUiLoader, QObjectBinding )
00038 KJSO_QOBJECT_BIND( UiLoaderBinding, QUiLoader )
00039 
00040 KJSO_START_CTOR( UiLoaderBinding, QUiLoader, 1 )
00041 {
00042   QUiLoader *uiLoader = 0;
00043   if ( args.size() == 0 )
00044   {
00045     uiLoader = new QUiLoader();
00046   }
00047   else if( args.size() == 1 )
00048   {
00049     QObject *arg0 = KJSEmbed::extractObject<QObject>(exec, args, 0, 0);
00050     uiLoader = new QUiLoader(arg0);
00051   }
00052   else
00053     return KJS::throwError(exec, KJS::GeneralError, i18n("Not enough arguments."));
00054   
00055   KJS::JSObject *uiLoaderBinding = new UiLoaderBinding( exec, uiLoader );
00056 //  qDebug() << "UiLoaderBinding::CTOR() args.size()=" << args.size() << " uiLoader=" << uiLoader << " uiLoaderBinding=" << uiLoaderBinding;
00057   return uiLoaderBinding;
00058 }
00059 KJSO_END_CTOR
00060 
00061 namespace UiLoaderNS {
00062 START_QOBJECT_METHOD(createAction, QUiLoader )
00063 {
00064   QObject* parent = KJSEmbed::extractObject<QObject>(exec, args, 0, 0);
00065   QString actionName = KJSEmbed::extractQString(exec, args, 1);
00066   QAction* action = object->createAction(parent, actionName);
00067   if ( action )
00068     return KJSEmbed::createQObject( exec, action );
00069   else
00070     return KJS::throwError(exec, KJS::GeneralError, i18n("Failed to create Action.") );
00071 }
00072 END_QOBJECT_METHOD
00073 
00074 START_QOBJECT_METHOD(createActionGroup, QUiLoader )
00075   QObject* parent = KJSEmbed::extractObject<QObject>(exec, args, 0, 0);
00076   QString actionName = KJSEmbed::extractQString(exec, args, 1);
00077   QActionGroup* actionGroup = object->createActionGroup(parent, actionName);
00078   if ( actionGroup )
00079     return KJSEmbed::createQObject( exec, actionGroup );
00080   else
00081     return KJS::throwError(exec, KJS::GeneralError, i18n("Failed to create ActionGroup.") );
00082 END_QOBJECT_METHOD
00083 
00084 START_QOBJECT_METHOD(createLayout, QUiLoader )
00085 {
00086   QString className = KJSEmbed::extractQString(exec, args, 0);
00087   if (className.isEmpty())
00088     return KJS::throwError(exec, KJS::SyntaxError, i18n("No classname specified"));
00089   QObject* parent = KJSEmbed::extractObject<QObject>(exec, args, 1, 0);
00090   QString name = KJSEmbed::extractQString(exec, args, 2);
00091   QLayout* layout = object->createLayout(className, parent, name);
00092   if ( layout )
00093     return KJSEmbed::createQObject( exec, layout );
00094   else
00095     return KJS::throwError(exec, KJS::GeneralError, i18n("Failed to create Layout.") );
00096 }
00097 END_QOBJECT_METHOD
00098 
00099 START_QOBJECT_METHOD(createWidget, QUiLoader )
00100 {
00101   QString className = KJSEmbed::extractQString(exec, args, 0);
00102   if (className.isEmpty())
00103     return KJS::throwError(exec, KJS::SyntaxError, i18n("No classname specified."));
00104   QWidget* parent = KJSEmbed::extractObject<QWidget>(exec, args, 1, 0);
00105   QString name = KJSEmbed::extractQString(exec, args, 2);
00106   QWidget* widget = object->createWidget(className, parent, name);
00107   if ( widget )
00108     return KJSEmbed::createQObject( exec, widget );
00109   else
00110     return KJS::throwError(exec, KJS::GeneralError, i18n("Failed to create Widget.") );
00111 }
00112 END_QOBJECT_METHOD
00113 
00114 START_QOBJECT_METHOD(load, QUiLoader )
00115 {
00116   QString fileName = KJSEmbed::extractQString(exec, args, 0);
00117   if (fileName.isEmpty())
00118     return KJS::throwError(exec, KJS::SyntaxError, i18n("Must supply a filename."));
00119   
00120   QFile uiFile(fileName);
00121   if (! uiFile.open(QIODevice::ReadOnly | QIODevice::Text) )
00122       return KJS::throwError(exec, KJS::GeneralError, i18n("Could not open file '%1': %2", fileName, uiFile.errorString() ) );
00123   
00124   QWidget* parent = KJSEmbed::extractObject<QWidget>(exec, args, 1, 0);
00125 
00126   QWidget* widget = object->load(&uiFile, parent);
00127   uiFile.close();
00128   if (! widget )
00129     return KJS::throwError(exec, KJS::GeneralError, i18n("Failed to load file '%1'", fileName));
00130 
00131   KJS::JSObject* result = KJSEmbed::createQObject( exec, widget );
00132 //  qDebug() << "UiLoaderBinding::load(): fileName=" << fileName << "widget " << widget << " result=" << result << "(" << result->toString(exec).ascii() << ")";
00133   return result;  
00134 }
00135 END_QOBJECT_METHOD
00136 
00137 START_QOBJECT_METHOD(pluginPaths, QUiLoader )
00138 //  qDebug() << "UiLoader::pluginPaths(): " << object->pluginPaths();
00139   result = KJSEmbed::convertToValue( exec, QVariant(object->pluginPaths()) );
00140 END_QOBJECT_METHOD
00141 
00142 }
00143 
00144 START_METHOD_LUT( UiLoaderBinding )
00145     {"createAction", 0, KJS::DontDelete|KJS::ReadOnly, &UiLoaderNS::createAction},
00146     {"createActionGroup", 0, KJS::DontDelete|KJS::ReadOnly, &UiLoaderNS::createActionGroup},
00147     {"createLayout", 1, KJS::DontDelete|KJS::ReadOnly, &UiLoaderNS::createLayout},
00148     {"createWidget", 1, KJS::DontDelete|KJS::ReadOnly, &UiLoaderNS::createWidget},
00149     {"load", 1, KJS::DontDelete|KJS::ReadOnly, &UiLoaderNS::load},
00150     {"load", 2, KJS::DontDelete|KJS::ReadOnly, &UiLoaderNS::load},
00151     {"pluginPaths", 0, KJS::DontDelete|KJS::ReadOnly, &UiLoaderNS::pluginPaths}
00152 END_METHOD_LUT
00153 
00154 NO_ENUMS( UiLoaderBinding )
00155 NO_STATICS( UiLoaderBinding )
00156 
00157 
00158 //kate: indent-spaces on; indent-width 4; replace-tabs on; indent-mode cstyle;

kjsembed

Skip menu "kjsembed"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal