• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.1 API Reference
  • KDE Home
  • Contact Us
 

kjsembed

  • kjsembed
  • kjsembed
quiloader_binding.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2005, 2006 Ian Reinhart Geiser <geiseri@kde.org>
3  Copyright (C) 2005, 2006 Matt Broadstone <mbroadst@gmail.com>
4  Copyright (C) 2005, 2006 Richard J. Moore <rich@kde.org>
5  Copyright (C) 2005, 2006 Erik L. Bunce <kde@bunce.us>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 #include "quiloader_binding.h"
23 
24 #include <QtGui/QWidget>
25 #include <QtCore/QFile>
26 #include <QtCore/QDebug>
27 
28 #include "qwidget_binding.h"
29 #include "qobject_binding.h"
30 #include "qaction_binding.h"
31 #include "qlayout_binding.h"
32 #include "static_binding.h"
33 #include "kjseglobal.h"
34 
35 using namespace KJSEmbed;
36 
37 KJSO_SIMPLE_BINDING_CTOR( UiLoaderBinding, QUiLoader, QObjectBinding )
38 KJSO_QOBJECT_BIND( UiLoaderBinding, QUiLoader )
39 
40 KJSO_START_CTOR( UiLoaderBinding, QUiLoader, 1 )
41 {
42  QUiLoader *uiLoader = 0;
43  if ( args.size() == 0 )
44  {
45  uiLoader = new QUiLoader();
46  }
47  else if( args.size() == 1 )
48  {
49  QObject *arg0 = KJSEmbed::extractObject<QObject>(exec, args, 0, 0);
50  uiLoader = new QUiLoader(arg0);
51  }
52  else
53  return KJS::throwError(exec, KJS::GeneralError, i18n("Not enough arguments."));
54 
55  KJS::JSObject *uiLoaderBinding = new UiLoaderBinding( exec, uiLoader );
56 // qDebug() << "UiLoaderBinding::CTOR() args.size()=" << args.size() << " uiLoader=" << uiLoader << " uiLoaderBinding=" << uiLoaderBinding;
57  return uiLoaderBinding;
58 }
59 KJSO_END_CTOR
60 
61 namespace UiLoaderNS {
62 START_QOBJECT_METHOD(createAction, QUiLoader )
63 {
64  QObject* parent = KJSEmbed::extractObject<QObject>(exec, args, 0, 0);
65  QString actionName = KJSEmbed::extractQString(exec, args, 1);
66  QAction* action = object->createAction(parent, actionName);
67  if ( action )
68  return KJSEmbed::createQObject( exec, action );
69  else
70  return KJS::throwError(exec, KJS::GeneralError, i18n("Failed to create Action.") );
71 }
72 END_QOBJECT_METHOD
73 
74 START_QOBJECT_METHOD(createActionGroup, QUiLoader )
75  QObject* parent = KJSEmbed::extractObject<QObject>(exec, args, 0, 0);
76  QString actionName = KJSEmbed::extractQString(exec, args, 1);
77  QActionGroup* actionGroup = object->createActionGroup(parent, actionName);
78  if ( actionGroup )
79  return KJSEmbed::createQObject( exec, actionGroup );
80  else
81  return KJS::throwError(exec, KJS::GeneralError, i18n("Failed to create ActionGroup.") );
82 END_QOBJECT_METHOD
83 
84 START_QOBJECT_METHOD(createLayout, QUiLoader )
85 {
86  QString className = KJSEmbed::extractQString(exec, args, 0);
87  if (className.isEmpty())
88  return KJS::throwError(exec, KJS::SyntaxError, i18n("No classname specified"));
89  QObject* parent = KJSEmbed::extractObject<QObject>(exec, args, 1, 0);
90  QString name = KJSEmbed::extractQString(exec, args, 2);
91  QLayout* layout = object->createLayout(className, parent, name);
92  if ( layout )
93  return KJSEmbed::createQObject( exec, layout );
94  else
95  return KJS::throwError(exec, KJS::GeneralError, i18n("Failed to create Layout.") );
96 }
97 END_QOBJECT_METHOD
98 
99 START_QOBJECT_METHOD(createWidget, QUiLoader )
100 {
101  QString className = KJSEmbed::extractQString(exec, args, 0);
102  if (className.isEmpty())
103  return KJS::throwError(exec, KJS::SyntaxError, i18n("No classname specified."));
104  QWidget* parent = KJSEmbed::extractObject<QWidget>(exec, args, 1, 0);
105  QString name = KJSEmbed::extractQString(exec, args, 2);
106  QWidget* widget = object->createWidget(className, parent, name);
107  if ( widget )
108  return KJSEmbed::createQObject( exec, widget );
109  else
110  return KJS::throwError(exec, KJS::GeneralError, i18n("Failed to create Widget.") );
111 }
112 END_QOBJECT_METHOD
113 
114 START_QOBJECT_METHOD(load, QUiLoader )
115 {
116  QString fileName = KJSEmbed::extractQString(exec, args, 0);
117  if (fileName.isEmpty())
118  return KJS::throwError(exec, KJS::SyntaxError, i18n("Must supply a filename."));
119 
120  QFile uiFile(fileName);
121  if (! uiFile.open(QIODevice::ReadOnly | QIODevice::Text) )
122  return KJS::throwError(exec, KJS::GeneralError, i18n("Could not open file '%1': %2", fileName, uiFile.errorString() ) );
123 
124  QWidget* parent = KJSEmbed::extractObject<QWidget>(exec, args, 1, 0);
125 
126  QWidget* widget = object->load(&uiFile, parent);
127  uiFile.close();
128  if (! widget )
129  return KJS::throwError(exec, KJS::GeneralError, i18n("Failed to load file '%1'", fileName));
130 
131  KJS::JSObject* result = KJSEmbed::createQObject( exec, widget );
132 // qDebug() << "UiLoaderBinding::load(): fileName=" << fileName << "widget " << widget << " result=" << result << "(" << result->toString(exec).ascii() << ")";
133  return result;
134 }
135 END_QOBJECT_METHOD
136 
137 START_QOBJECT_METHOD(pluginPaths, QUiLoader )
138 // qDebug() << "UiLoader::pluginPaths(): " << object->pluginPaths();
139  result = KJSEmbed::convertToValue( exec, QVariant(object->pluginPaths()) );
140 END_QOBJECT_METHOD
141 
142 }
143 
144 START_METHOD_LUT( UiLoaderBinding )
145  {"createAction", 0, KJS::DontDelete|KJS::ReadOnly, &UiLoaderNS::createAction},
146  {"createActionGroup", 0, KJS::DontDelete|KJS::ReadOnly, &UiLoaderNS::createActionGroup},
147  {"createLayout", 1, KJS::DontDelete|KJS::ReadOnly, &UiLoaderNS::createLayout},
148  {"createWidget", 1, KJS::DontDelete|KJS::ReadOnly, &UiLoaderNS::createWidget},
149  {"load", 1, KJS::DontDelete|KJS::ReadOnly, &UiLoaderNS::load},
150  {"load", 2, KJS::DontDelete|KJS::ReadOnly, &UiLoaderNS::load},
151  {"pluginPaths", 0, KJS::DontDelete|KJS::ReadOnly, &UiLoaderNS::pluginPaths}
152 END_METHOD_LUT
153 
154 NO_ENUMS( UiLoaderBinding )
155 NO_STATICS( UiLoaderBinding )
156 
157 
158 //kate: indent-spaces on; indent-width 4; replace-tabs on; indent-mode cstyle;
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Wed Mar 20 2013 07:15:43 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kjsembed

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

kdelibs-4.10.1 API Reference

Skip menu "kdelibs-4.10.1 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal