From b89a2bea5731100edc59c6d7eff3f905091044ae Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Sat, 14 Nov 2009 07:19:25 +0000 Subject: [PATCH] first run at a file dialog wrapper svn path=/trunk/KDE/kdebase/runtime/; revision=1048908 --- .../javascript/qtgui/filedialogproxy.cpp | 122 ++++++++++++++++++ .../javascript/qtgui/filedialogproxy.h | 72 +++++++++++ 2 files changed, 194 insertions(+) create mode 100644 scriptengines/javascript/qtgui/filedialogproxy.cpp create mode 100644 scriptengines/javascript/qtgui/filedialogproxy.h diff --git a/scriptengines/javascript/qtgui/filedialogproxy.cpp b/scriptengines/javascript/qtgui/filedialogproxy.cpp new file mode 100644 index 000000000..855e562fd --- /dev/null +++ b/scriptengines/javascript/qtgui/filedialogproxy.cpp @@ -0,0 +1,122 @@ +/* + * Copyright 2009 Aaron J. Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library 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 "filedialogproxy.h" + +FileDialogProxy::FileDialogProxy(KFileDialog::OperationMode mode, QObject *parent) + : QObject(parent), + m_dialog(new KFileDialog(KUrl("~"), QString(), 0)) +{ + m_dialog->setOperationMode(mode); + connect(m_dialog, SIGNAL(okClicked()), this, SIGNAL(finished())); +} + +FileDialogProxy::~FileDialogProxy() +{ + delete m_dialog; +} + +KUrl FileDialogProxy::selectedUrl() const +{ + return m_dialog->selectedUrl(); +} + +void FileDialogProxy::setUrl(const KUrl &url) +{ + m_dialog->setUrl(url); +} + +KUrl::List FileDialogProxy::selectedUrls() const +{ + return m_dialog->selectedUrls(); +} + +KUrl FileDialogProxy::baseUrl() const +{ + return m_dialog->baseUrl(); +} + +QString FileDialogProxy::selectedFile() const +{ + return m_dialog->selectedFile(); +} + +QStringList FileDialogProxy::selectedFiles() const +{ + return m_dialog->selectedFiles(); +} + +QString FileDialogProxy::filter() const +{ + return m_dialog->currentFilter(); +} + +void FileDialogProxy::setFilter(const QString &filter) +{ + m_dialog->setFilter(filter); +} + +bool FileDialogProxy::localOnly() const +{ + return m_dialog->mode() & KFile::LocalOnly; +} + +void FileDialogProxy::setLocalOnly(bool localOnly) +{ + if (localOnly) { + m_dialog->setMode(m_dialog->mode() ^ KFile::LocalOnly); + } else { + m_dialog->setMode(m_dialog->mode() | KFile::LocalOnly); + } +} + +bool FileDialogProxy::directoriesOnly() const +{ + return m_dialog->mode() & KFile::Directory; +} + +void FileDialogProxy::setDirectoriesOnly(bool directoriesOnly) +{ + if (directoriesOnly) { + m_dialog->setMode(m_dialog->mode() ^ KFile::Directory); + } else { + m_dialog->setMode(m_dialog->mode() | KFile::Directory); + } +} + +bool FileDialogProxy::existingOnly() const +{ + return m_dialog->mode() & KFile::ExistingOnly; +} + +void FileDialogProxy::setExistingOnly(bool existingOnly) +{ + if (existingOnly) { + m_dialog->setMode(m_dialog->mode() ^ KFile::ExistingOnly); + } else { + m_dialog->setMode(m_dialog->mode() | KFile::ExistingOnly); + } +} + +void FileDialogProxy::show() +{ + m_dialog->show(); +} + +#include "filedialogproxy.moc" + diff --git a/scriptengines/javascript/qtgui/filedialogproxy.h b/scriptengines/javascript/qtgui/filedialogproxy.h new file mode 100644 index 000000000..d6c5c07e9 --- /dev/null +++ b/scriptengines/javascript/qtgui/filedialogproxy.h @@ -0,0 +1,72 @@ +/* + * Copyright 2009 Aaron J. Seigo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 as + * published by the Free Software Foundation + * + * 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 Library 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. + */ + +#ifndef FILEDIALOGPROXY_H +#define FILEDIALOGPROXY_H + +#include +#include + +class FileDialogProxy : public QObject +{ + Q_OBJECT + Q_PROPERTY(KUrl url READ selectedUrl WRITE setUrl) + Q_PROPERTY(KUrl::List urls READ selectedUrls) + Q_PROPERTY(KUrl baseUrl READ baseUrl) + Q_PROPERTY(QString file READ selectedFile) + Q_PROPERTY(QStringList files READ selectedFiles) + Q_PROPERTY(QString filter READ filter WRITE setFilter) + Q_PROPERTY(bool localOnly READ localOnly WRITE setLocalOnly) + Q_PROPERTY(bool directoriesOnly READ directoriesOnly WRITE setDirectoriesOnly) + Q_PROPERTY(bool existingOnly READ existingOnly WRITE setExistingOnly) + +public: + FileDialogProxy(KFileDialog::OperationMode mode, QObject *parent = 0); + ~FileDialogProxy(); + + KUrl selectedUrl() const; + void setUrl(const KUrl &url); + + KUrl::List selectedUrls() const; + KUrl baseUrl() const; + QString selectedFile() const; + QStringList selectedFiles() const; + + QString filter() const; + void setFilter(const QString &filter); + + bool localOnly() const; + void setLocalOnly(bool localOnly); + + bool directoriesOnly() const; + void setDirectoriesOnly(bool directoriesOnly); + + bool existingOnly() const; + void setExistingOnly(bool existingOnly); + +public Q_SLOTS: + void show(); + +Q_SIGNALS: + void finished(); + +private: + KFileDialog *m_dialog; +}; + +#endif