summaryrefslogtreecommitdiffstats
path: root/kjsembed/plugins/tdefileitemloader.cpp
blob: 6ab7cc452d63696ad663a1704197b17b6d5f2550 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/***************************************************************************
 *   Copyright (C) 2004 by ian reinhart geiser                             *
 *   [email protected]                                                       *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/
#include "tdefileitemloader.h"

#include <kjsembed/jsopaqueproxy.h>
#include <kjsembed/jsbinding.h>
#include <kjsembed/jsfactory.h>
#include <kjsembed/jsfactory_imp.h>
#include <kjsembed/kjsembedpart.h>

#include <tdefileitem.h>
#include <kdebug.h>

namespace KJSEmbed {
namespace Bindings {

KFileItemLoader::KFileItemLoader(TQObject *parent, const char *name, const TQStringList &args)
 : JSBindingPlugin(parent, name, args)
{
}


KFileItemLoader::~KFileItemLoader()
{
}

KJS::Object KFileItemLoader::createBinding(KJSEmbedPart *jspart, KJS::ExecState *exec, const KJS::List &args) const
{
        kdDebug() << "Loading a KFileItem object" << endl;
        JSOpaqueProxy *prx = new JSOpaqueProxy(  (void *) 0, "KFileItem" );

        KJS::Object proxyObj(prx);
        KFileItemImp::addBindings( exec, proxyObj );
        return proxyObj;
}

} // Bindings
} // KJSEmbed

KJSEmbed::Bindings::KFileItemImp::KFileItemImp( KJS::ExecState * exec, int id )
: JSProxyImp(exec), mid(id)
{

}

KJSEmbed::Bindings::KFileItemImp::~ KFileItemImp( )
{

}

void KJSEmbed::Bindings::KFileItemImp::addBindings( KJS::ExecState * exec, KJS::Object & object )
{

	JSOpaqueProxy *op = JSProxy::toOpaqueProxy( object.imp() );
	if ( !op ) 
	{
		kdWarning() << "KFileItemImp::addBindings() failed, not a JSOpaqueProxy" << endl;
		return;
	}
	
	if ( op->typeName() != "KFileItem" ) 
	{
		kdWarning() << "KFileItemImp::addBindings() failed, type is " << op->typeName() <<
	endl;
		return;
	}
	
	JSProxy::MethodTable methods[] = {
		{ Methodrefresh, "refresh"},
		{ MethodrefreshMimeType, "refreshMimeType"},
		{ Methodurl, "url"},
		{ MethodsetUrl, "setUrl"},
		{ MethodsetName, "setName"},
		{ MethodpermissionsString, "permissionsString"},
		{ Methoduser, "user"},
		{ Methodgroup, "group"},
		{ MethodisLink, "isLink"},
		{ MethodisDir, "isDir"},
		{ MethodisFile, "isFile"},
		{ MethodisReadable, "isReadable"},
		{ MethodlinkDest, "linkDest"},
		{ MethodtimeString, "timeString"}, 
		{ MethodisLocalFile, "isLocalFile"},
		{ Methodtext, "text"},
		{ Methodname, "name"}, 
		{ MethodmimeType, "mimeType"},
		{ MethodisMimeTypeKnown, "isMimeTypeKnown"},
		{ MethodmimeComment, "mimeComment"},
		{ MethodiconName, "iconName"},
		{ Methodpixmap, "pixmap"},
		{ Methodoverlays, "overlays"},
		{ MethodgetStatusBarInfo, "getStatusBarInfo"},
		{ MethodgetToolTipText, "getToolTipText"}, 
		{ Methodrun, "run"},
		{ 0, 0 }
	};
	
	int idx = 0;
	do {
		KFileItemImp *meth = new KFileItemImp( exec, methods[idx].id );
		object.put( exec , methods[idx].name, KJS::Object(meth) );
		++idx;
	} while( methods[idx].id );

}

KJS::Value KJSEmbed::Bindings::KFileItemImp::call( KJS::ExecState * exec, KJS::Object & self, const KJS::List & args )
{
	kdDebug() << "KFileItemImp::call() " << mid << endl;
	JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() );
	if ( !op ) {
		kdWarning() << "KFileItemImp::call() failed, not a JSOpaqueProxy" << endl;
		return KJS::Value();
	}
	
	if ( op->typeName() != "KFileItem" ) {
		kdWarning() << "KFileItemImp::call() failed, type is " << op->typeName() << endl;
		return KJS::Value();
	}
	
	KFileItem *obj = op->toNative<KFileItem >();
	
	KJS::Value retValue = KJS::Value();
	switch ( mid ) {
	case Methodrefresh:
		obj->refresh();
		break;
	case MethodrefreshMimeType:
		obj->refreshMimeType(); 
		break;
	case Methodurl:
	{
		TQString url = obj->url().url();
		retValue = KJS::String(url);
		break;
	}
	case MethodsetUrl:
	{
		TQString url = extractTQString(exec, args, 0);
		obj->setURL(url);
		break;
	}
	case MethodsetName: 
	case MethodpermissionsString: 
	case Methoduser: 
	case Methodgroup: 
	case MethodisLink: 
	case MethodisDir: 
	case MethodisFile: 
	case MethodisReadable: 
	case MethodlinkDest: 
	case MethodtimeString: 
	case MethodisLocalFile: 
	case Methodtext:
	{
		retValue = convertToValue(exec, obj->text() );
		break;
	} 
	case Methodname:  
	case MethodmimeType: 
	case MethodisMimeTypeKnown: 
	case MethodmimeComment: 
	case MethodiconName: 
	{
		retValue = convertToValue( exec, obj->iconName() );
		break;
	}
	case Methodpixmap:
	{
		int size = extractInt(exec, args, 0);
		int state = extractInt(exec, args, 1);
		retValue = convertToValue(exec, obj->pixmap(size, state));
		break;
	}
	case Methodoverlays: 
	{
		retValue = convertToValue(exec, obj->overlays());
		break;
	}
	case MethodgetStatusBarInfo: 
	{
		retValue = KJS::String( obj->getStatusBarInfo() );
		break;
	}
	case MethodgetToolTipText:
	{
		int maxcount = extractInt(exec, args, 0);
		retValue = KJS::String(obj->getToolTipText(maxcount));
		break;
	}
	case Methodrun:
		obj->run();
		break;
	default:
		kdWarning() << "KFileItemImp has no method " << mid << endl;
		break;
	}
	
	op->setValue((void*) obj, "KFileItem");
	return retValue;

} 

#include <kgenericfactory.h>
typedef KGenericFactory<KJSEmbed::Bindings::KFileItemLoader> KFileItemLoaderFactory;
K_EXPORT_COMPONENT_FACTORY( libfileitemplugin, KFileItemLoaderFactory( "KFileItemLoader" ) )