kjsembed
filedialog_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 "filedialog_binding.h" 00023 00024 #include <QtCore/QStringList> 00025 #include <QtCore/QProcess> 00026 #include <QtGui/QFileDialog> 00027 #include <QtCore/QDebug> 00028 00029 #include <kjs/object.h> 00030 00031 #include "static_binding.h" 00032 00033 using namespace KJSEmbed; 00034 00035 KJS::JSValue *callGetExistingDirectory( KJS::ExecState *exec, KJS::JSObject * /*self*/, const KJS::List &args ) 00036 { 00037 QWidget *parent = KJSEmbed::extractObject<QWidget>(exec, args, 0, 0); 00038 QString caption = KJSEmbed::extractVariant<QString>(exec, args, 1, QString()); 00039 QString dir = KJSEmbed::extractVariant<QString>(exec, args, 2, QString()); 00040 QFileDialog::Options options = (QFileDialog::Options)KJSEmbed::extractVariant<uint>(exec, args, 3, QFileDialog::ShowDirsOnly); 00041 00042 return KJS::jsString( QFileDialog::getExistingDirectory(parent, caption, dir, options) ); 00043 } 00044 00045 KJS::JSValue *callGetOpenFileName( KJS::ExecState *exec, KJS::JSObject * /*self*/, const KJS::List &args ) 00046 { 00047 QWidget *parent = KJSEmbed::extractObject<QWidget>(exec, args, 0, 0); 00048 QString caption = KJSEmbed::extractVariant<QString>(exec, args, 1, ""); 00049 QString dir = KJSEmbed::extractVariant<QString>(exec, args, 2, ""); 00050 QString filter = KJSEmbed::extractVariant<QString>(exec, args, 3, ""); 00051 // QString *selectedFilter = KJSEmbed::extractVariant<QString>(exec, args, 4, 0); 00052 QFileDialog::Options options = (QFileDialog::Options)KJSEmbed::extractVariant<uint>(exec, args, 4, 0); 00053 00054 return KJS::jsString( QFileDialog::getOpenFileName(parent, caption, dir, filter, 0, options) ); 00055 } 00056 00057 KJS::JSValue *callGetOpenFileNames( KJS::ExecState *exec, KJS::JSObject * /*self*/, const KJS::List &args ) 00058 { 00059 QWidget *parent = KJSEmbed::extractObject<QWidget>(exec, args, 0, 0); 00060 QString caption = KJSEmbed::extractVariant<QString>(exec, args, 1, QString()); 00061 QString dir = KJSEmbed::extractVariant<QString>(exec, args, 2, QString()); 00062 QString filter = KJSEmbed::extractVariant<QString>(exec, args, 3, QString()); 00063 // QString *selectedFilter = KJSEmbed::extractVariant<QString>(exec, args, 4, 0); 00064 QFileDialog::Options options = (QFileDialog::Options)KJSEmbed::extractVariant<uint>(exec, args, 4, 0); 00065 00066 QStringList fileNames = QFileDialog::getOpenFileNames(parent, caption, dir, filter, 0, options); 00067 00068 return convertToValue(exec, fileNames); 00069 } 00070 00071 KJS::JSValue *callGetSaveFileName( KJS::ExecState *exec, KJS::JSObject * /*self*/, const KJS::List &args ) 00072 { 00073 QWidget *parent = KJSEmbed::extractObject<QWidget>(exec, args, 0, 0); 00074 QString caption = KJSEmbed::extractVariant<QString>(exec, args, 1, QString()); 00075 QString dir = KJSEmbed::extractVariant<QString>(exec, args, 2, QString()); 00076 QString filter = KJSEmbed::extractVariant<QString>(exec, args, 3, QString()); 00077 // QString *selectedFilter = KJSEmbed::extractVariant<QString>(exec, args, 4, 0); 00078 QFileDialog::Options options = (QFileDialog::Options)KJSEmbed::extractVariant<uint>(exec, args, 4, 0); 00079 00080 return KJS::jsString( QFileDialog::getSaveFileName(parent, caption, dir, filter, 0, options) ); 00081 } 00082 const Method FileDialog::FileDialogMethods[] = 00083 { 00084 {"getExistingDirectory", 1, KJS::DontDelete|KJS::ReadOnly, &callGetExistingDirectory }, 00085 {"getOpenFileName", 1, KJS::DontDelete|KJS::ReadOnly, &callGetOpenFileName }, 00086 {"getOpenFileNames", 1, KJS::DontDelete|KJS::ReadOnly, &callGetOpenFileNames }, 00087 {"getSaveFileName", 0, KJS::DontDelete|KJS::ReadOnly, &callGetSaveFileName }, 00088 {0, 0, 0, 0 } 00089 }; 00090 //kate: indent-spaces on; indent-width 4; replace-tabs on; indent-mode cstyle;
KDE 4.6 API Reference