mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 584217 - Add Meego Touch based filepicker implementation. r=jeremias.bosch,florian.haenel
This commit is contained in:
parent
1e9a422ca0
commit
ebc7020bfe
@ -547,6 +547,7 @@ MOZ_ENABLE_QMSYSTEM2 = @MOZ_ENABLE_QMSYSTEM2@
|
||||
MOZ_ENABLE_QTMOBILITY = @MOZ_ENABLE_QTMOBILITY@
|
||||
MOZ_ENABLE_CONTENTACTION = @MOZ_ENABLE_CONTENTACTION@
|
||||
MOZ_ENABLE_MEEGOTOUCHSHARE = @MOZ_ENABLE_MEEGOTOUCHSHARE@
|
||||
MOZ_ENABLE_CONTENTMANAGER = @MOZ_ENABLE_CONTENTMANAGER@
|
||||
|
||||
MOZ_DBUS_CFLAGS = @MOZ_DBUS_CFLAGS@
|
||||
MOZ_DBUS_LIBS = @MOZ_DBUS_LIBS@
|
||||
|
@ -1020,6 +1020,14 @@ proxy.h
|
||||
#if MOZ_PLATFORM_MAEMO==6
|
||||
contentaction/contentaction.h
|
||||
#endif
|
||||
#ifdef MOZ_ENABLE_CONTENTMANAGER
|
||||
SelectSingleContentItemPage.h
|
||||
SelectMultipleContentItemsPage.h
|
||||
QtSparql/qsparqlconnection.h
|
||||
QtSparql/qsparqlquery.h
|
||||
QtSparql/qsparqlresult.h
|
||||
#endif
|
||||
|
||||
#if MOZ_TREE_PIXMAN!=1
|
||||
pixman.h
|
||||
#endif
|
||||
|
14
configure.in
14
configure.in
@ -6521,6 +6521,20 @@ if test $MOZ_PLATFORM_MAEMO; then
|
||||
|
||||
fi
|
||||
if test $MOZ_PLATFORM_MAEMO = 6; then
|
||||
|
||||
PKG_CHECK_MODULES(LIBCONTENTMANAGER, ContentManager QtSparql,
|
||||
_LIB_FOUND=1,
|
||||
_LIB_FOUND=)
|
||||
if test "$_LIB_FOUND"; then
|
||||
MOZ_PLATFORM_MAEMO_LIBS="$MOZ_PLATFORM_MAEMO_LIBS $LIBCONTENTMANAGER_LIBS"
|
||||
MOZ_PLATFORM_MAEMO_CFLAGS="$MOZ_PLATFORM_MAEMO_CFLAGS $LIBCONTENTMANAGER_CFLAGS"
|
||||
MOZ_ENABLE_CONTENTMANAGER=1
|
||||
AC_DEFINE(MOZ_ENABLE_CONTENTMANAGER)
|
||||
else
|
||||
AC_MSG_WARN([Cannot find libcontentmanager and or QtSparql building for Maemo 6])
|
||||
fi
|
||||
AC_SUBST(MOZ_ENABLE_CONTENTMANAGER)
|
||||
|
||||
dnl ========================================================
|
||||
dnl = Enable meego libcontentaction
|
||||
dnl ========================================================
|
||||
|
@ -1020,6 +1020,14 @@ proxy.h
|
||||
#if MOZ_PLATFORM_MAEMO==6
|
||||
contentaction/contentaction.h
|
||||
#endif
|
||||
#ifdef MOZ_ENABLE_CONTENTMANAGER
|
||||
SelectSingleContentItemPage.h
|
||||
SelectMultipleContentItemsPage.h
|
||||
QtSparql/qsparqlconnection.h
|
||||
QtSparql/qsparqlquery.h
|
||||
QtSparql/qsparqlresult.h
|
||||
#endif
|
||||
|
||||
#if MOZ_TREE_PIXMAN!=1
|
||||
pixman.h
|
||||
#endif
|
||||
|
@ -57,7 +57,14 @@ MOCSRCS = \
|
||||
moc_nsAppShell.cpp \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
ifdef MOZ_ENABLE_CONTENTMANAGER
|
||||
MOCSRCS += moc_nsMFilePicker.cpp \
|
||||
$(NULL)
|
||||
CPPSRCS += nsMFilePicker.cpp \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
CPPSRCS += \
|
||||
$(MOCSRCS) \
|
||||
nsAppShell.cpp \
|
||||
nsWidgetFactory.cpp \
|
||||
@ -102,8 +109,8 @@ include $(topsrcdir)/config/config.mk
|
||||
include $(topsrcdir)/ipc/chromium/chromium-config.mk
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
CXXFLAGS += $(MOZ_QT_CFLAGS) $(GLIB_CFLAGS) $(MOZ_CAIRO_CFLAGS)
|
||||
CFLAGS += $(MOZ_QT_CFLAGS) $(GLIB_CFLAGS) $(MOZ_CAIRO_CFLAGS)
|
||||
CXXFLAGS += $(MOZ_QT_CFLAGS) $(GLIB_CFLAGS) $(MOZ_CAIRO_CFLAGS) $(MOZ_PLATFORM_MAEMO_CFLAGS)
|
||||
CFLAGS += $(MOZ_QT_CFLAGS) $(GLIB_CFLAGS) $(MOZ_CAIRO_CFLAGS) $(MOZ_PLATFORM_MAEMO_CFLAGS)
|
||||
|
||||
DEFINES += -D_IMPL_NS_WIDGET
|
||||
#DEFINES += -DDEBUG_WIDGETS
|
||||
|
@ -38,30 +38,39 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsFilePicker.h"
|
||||
#include <QStringList>
|
||||
#include <QGraphicsWidget>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsView>
|
||||
#include <QTemporaryFile>
|
||||
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsEnumeratorUtils.h"
|
||||
#ifdef MOZ_ENABLE_CONTENTMANAGER
|
||||
#include "nsMFilePicker.h"
|
||||
#define MozFileDialog MeegoFileDialog
|
||||
#else
|
||||
#include <QFileDialog>
|
||||
#define MozFileDialog QFileDialog
|
||||
#endif
|
||||
|
||||
|
||||
#include "nsFilePicker.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "mozqwidget.h"
|
||||
#include "nsWindow.h"
|
||||
#include "prlog.h"
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
static PRLogModuleInfo* sFilePickerLog = nsnull;
|
||||
#endif
|
||||
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
|
||||
//-----------------------------
|
||||
|
||||
/* Implementation file */
|
||||
NS_IMPL_ISUPPORTS1(nsFilePicker, nsIFilePicker)
|
||||
|
||||
nsFilePicker::nsFilePicker()
|
||||
: mDialog(0),
|
||||
mMode(nsIFilePicker::modeOpen)
|
||||
: mMode(nsIFilePicker::modeOpen)
|
||||
{
|
||||
#ifdef PR_LOGGING
|
||||
if (!sFilePickerLog)
|
||||
@ -74,7 +83,7 @@ nsFilePicker::~nsFilePicker()
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFilePicker::Init(nsIDOMWindow *parent, const nsAString & title, PRInt16 mode)
|
||||
nsFilePicker::Init(nsIDOMWindow* parent, const nsAString& title, PRInt16 mode)
|
||||
{
|
||||
return nsBaseFilePicker::Init(parent, title, mode);
|
||||
}
|
||||
@ -88,7 +97,7 @@ nsFilePicker::AppendFilters(PRInt32 filterMask)
|
||||
|
||||
/* void appendFilter (in AString title, in AString filter); */
|
||||
NS_IMETHODIMP
|
||||
nsFilePicker::AppendFilter(const nsAString & aTitle, const nsAString & aFilter)
|
||||
nsFilePicker::AppendFilter(const nsAString& aTitle, const nsAString& aFilter)
|
||||
{
|
||||
if (aFilter.Equals(NS_LITERAL_STRING("..apps"))) {
|
||||
// No platform specific thing we can do here, really....
|
||||
@ -107,13 +116,13 @@ nsFilePicker::AppendFilter(const nsAString & aTitle, const nsAString & aFilter)
|
||||
|
||||
/* attribute AString defaultString; */
|
||||
NS_IMETHODIMP
|
||||
nsFilePicker::GetDefaultString(nsAString & aDefaultString)
|
||||
nsFilePicker::GetDefaultString(nsAString& aDefaultString)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFilePicker::SetDefaultString(const nsAString & aDefaultString)
|
||||
nsFilePicker::SetDefaultString(const nsAString& aDefaultString)
|
||||
{
|
||||
mDefault = aDefaultString;
|
||||
|
||||
@ -122,14 +131,15 @@ nsFilePicker::SetDefaultString(const nsAString & aDefaultString)
|
||||
|
||||
/* attribute AString defaultExtension; */
|
||||
NS_IMETHODIMP
|
||||
nsFilePicker::GetDefaultExtension(nsAString & aDefaultExtension)
|
||||
nsFilePicker::GetDefaultExtension(nsAString& aDefaultExtension)
|
||||
{
|
||||
aDefaultExtension = mDefaultExtension;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFilePicker::SetDefaultExtension(const nsAString & aDefaultExtension)
|
||||
nsFilePicker::SetDefaultExtension(const nsAString& aDefaultExtension)
|
||||
{
|
||||
mDefaultExtension = aDefaultExtension;
|
||||
|
||||
@ -138,12 +148,13 @@ nsFilePicker::SetDefaultExtension(const nsAString & aDefaultExtension)
|
||||
|
||||
/* attribute long filterIndex; */
|
||||
NS_IMETHODIMP
|
||||
nsFilePicker::GetFilterIndex(PRInt32 *aFilterIndex)
|
||||
nsFilePicker::GetFilterIndex(PRInt32* aFilterIndex)
|
||||
{
|
||||
*aFilterIndex = mSelectedType;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFilePicker::SetFilterIndex(PRInt32 aFilterIndex)
|
||||
{
|
||||
@ -154,7 +165,7 @@ nsFilePicker::SetFilterIndex(PRInt32 aFilterIndex)
|
||||
|
||||
/* readonly attribute nsILocalFile file; */
|
||||
NS_IMETHODIMP
|
||||
nsFilePicker::GetFile(nsILocalFile * *aFile)
|
||||
nsFilePicker::GetFile(nsILocalFile* *aFile)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFile);
|
||||
|
||||
@ -175,7 +186,7 @@ nsFilePicker::GetFile(nsILocalFile * *aFile)
|
||||
|
||||
/* readonly attribute nsIFileURL fileURL; */
|
||||
NS_IMETHODIMP
|
||||
nsFilePicker::GetFileURL(nsIURI * *aFileURL)
|
||||
nsFilePicker::GetFileURL(nsIURI* *aFileURL)
|
||||
{
|
||||
nsCOMPtr<nsILocalFile> file;
|
||||
GetFile(getter_AddRefs(file));
|
||||
@ -189,7 +200,7 @@ nsFilePicker::GetFileURL(nsIURI * *aFileURL)
|
||||
|
||||
/* readonly attribute nsISimpleEnumerator files; */
|
||||
NS_IMETHODIMP
|
||||
nsFilePicker::GetFiles(nsISimpleEnumerator * *aFiles)
|
||||
nsFilePicker::GetFiles(nsISimpleEnumerator* *aFiles)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFiles);
|
||||
|
||||
@ -202,94 +213,121 @@ nsFilePicker::GetFiles(nsISimpleEnumerator * *aFiles)
|
||||
|
||||
/* short show (); */
|
||||
NS_IMETHODIMP
|
||||
nsFilePicker::Show(PRInt16 *aReturn)
|
||||
nsFilePicker::Show(PRInt16* aReturn)
|
||||
{
|
||||
nsCAutoString directory;
|
||||
if (mDisplayDirectory) {
|
||||
mDisplayDirectory->GetNativePath(directory);
|
||||
}
|
||||
|
||||
switch (mMode) {
|
||||
case nsIFilePicker::modeOpen:
|
||||
break;
|
||||
case nsIFilePicker::modeOpenMultiple:
|
||||
mDialog->setFileMode(QFileDialog::ExistingFiles);
|
||||
break;
|
||||
case nsIFilePicker::modeSave:
|
||||
mDialog->setFileMode(QFileDialog::AnyFile);
|
||||
mDialog->setAcceptMode(QFileDialog::AcceptSave);
|
||||
break;
|
||||
case nsIFilePicker::modeGetFolder:
|
||||
mDialog->setFileMode(QFileDialog::DirectoryOnly);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
mDialog->selectFile(QString::fromUtf16(mDefault.get()));
|
||||
|
||||
mDialog->setDirectory(directory.get());
|
||||
|
||||
QStringList filters;
|
||||
PRUint32 count = mFilters.Length();
|
||||
for (PRUint32 i = 0; i < count; ++i) {
|
||||
filters.append( mFilters[i].get() );
|
||||
filters.append(mFilters[i].get());
|
||||
}
|
||||
mDialog->setFilters(filters);
|
||||
|
||||
switch (mDialog->exec()) {
|
||||
case QDialog::Accepted: {
|
||||
QStringList files = mDialog->selectedFiles();
|
||||
QString selected;
|
||||
if (!files.isEmpty())
|
||||
{
|
||||
selected = files[0];
|
||||
QGraphicsWidget* parentWidget = 0;
|
||||
if (mParent) {
|
||||
parentWidget = static_cast<QGraphicsWidget*>
|
||||
(mParent->GetNativeData(NS_NATIVE_WIDGET));
|
||||
}
|
||||
|
||||
QWidget* parentQWidget = 0;
|
||||
if (parentWidget && parentWidget->scene()) {
|
||||
if (parentWidget->scene()->views().size()>0) {
|
||||
parentQWidget = parentWidget->scene()->views()[0];
|
||||
}
|
||||
}
|
||||
|
||||
QStringList files;
|
||||
QString selected;
|
||||
|
||||
switch (mMode) {
|
||||
case nsIFilePicker::modeOpen:
|
||||
selected = MozFileDialog::getOpenFileName(parentQWidget, mCaption,
|
||||
directory.get(), filters.join(";"));
|
||||
if (selected.isNull()) {
|
||||
*aReturn = nsIFilePicker::returnCancel;
|
||||
return NS_OK;
|
||||
}
|
||||
break;
|
||||
case nsIFilePicker::modeOpenMultiple:
|
||||
files = MozFileDialog::getOpenFileNames(parentQWidget, mCaption,
|
||||
directory.get(), filters.join(";"));
|
||||
if (files.empty()) {
|
||||
*aReturn = nsIFilePicker::returnCancel;
|
||||
return NS_OK;
|
||||
}
|
||||
selected = files[0];
|
||||
break;
|
||||
case nsIFilePicker::modeSave:
|
||||
{
|
||||
nsCOMPtr<nsIFile> targetFile;
|
||||
NS_GetSpecialDirectory(NS_UNIX_XDG_DOCUMENTS_DIR,
|
||||
getter_AddRefs(targetFile));
|
||||
if (!targetFile) {
|
||||
// failed to get the XDG directory, using $HOME for now
|
||||
NS_GetSpecialDirectory(NS_UNIX_HOME_DIR,
|
||||
getter_AddRefs(targetFile));
|
||||
}
|
||||
|
||||
QString path = QFile::encodeName(selected);
|
||||
PR_LOG(sFilePickerLog, PR_LOG_DEBUG, ("path is '%s'", path.toAscii().data()));
|
||||
mFile.Assign(path.toUtf8().data());
|
||||
*aReturn = nsIFilePicker::returnOK;
|
||||
if (mMode == modeSave) {
|
||||
nsCOMPtr<nsILocalFile> file;
|
||||
GetFile(getter_AddRefs(file));
|
||||
if (file) {
|
||||
PRBool exists = PR_FALSE;
|
||||
file->Exists(&exists);
|
||||
if (exists) {
|
||||
*aReturn = nsIFilePicker::returnReplace;
|
||||
}
|
||||
if (targetFile) {
|
||||
targetFile->Append(mDefault);
|
||||
nsString targetPath;
|
||||
targetFile->GetPath(targetPath);
|
||||
|
||||
PRBool exists = PR_FALSE;
|
||||
targetFile->Exists(&exists);
|
||||
if (exists) {
|
||||
// file exists already create temporary filename
|
||||
QTemporaryFile temp(QString::fromUtf16(targetPath.get()));
|
||||
temp.open();
|
||||
selected = temp.fileName();
|
||||
temp.close();
|
||||
} else {
|
||||
selected = QString::fromUtf16(targetPath.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case QDialog::Rejected: {
|
||||
*aReturn = nsIFilePicker::returnCancel;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case nsIFilePicker::modeGetFolder:
|
||||
selected = MozFileDialog::getExistingDirectory(parentQWidget, mCaption,
|
||||
directory.get());
|
||||
if (selected.isNull()) {
|
||||
*aReturn = nsIFilePicker::returnCancel;
|
||||
return NS_OK;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
*aReturn = nsIFilePicker::returnCancel;
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!selected.isEmpty()) {
|
||||
QString path = QFile::encodeName(selected);
|
||||
mFile.Assign(path.toUtf8().data());
|
||||
}
|
||||
|
||||
*aReturn = nsIFilePicker::returnOK;
|
||||
if (mMode == modeSave) {
|
||||
nsCOMPtr<nsILocalFile> file;
|
||||
GetFile(getter_AddRefs(file));
|
||||
if (file) {
|
||||
PRBool exists = PR_FALSE;
|
||||
file->Exists(&exists);
|
||||
if (exists) {
|
||||
*aReturn = nsIFilePicker::returnReplace;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsFilePicker::InitNative(nsIWidget *parent, const nsAString &title, PRInt16 mode)
|
||||
void nsFilePicker::InitNative(nsIWidget *aParent, const nsAString &aTitle, PRInt16 mode)
|
||||
{
|
||||
PR_LOG(sFilePickerLog, PR_LOG_DEBUG, ("nsFilePicker::InitNative"));
|
||||
|
||||
MozQWidget *parentMozWidget = (parent) ?
|
||||
static_cast<MozQWidget*>(parent->GetNativeData(NS_NATIVE_WIDGET)) : nsnull;
|
||||
QWidget *parentWidget = (parentMozWidget) ?
|
||||
parentMozWidget->getReceiver()->GetViewWidget() : nsnull;
|
||||
if (!parentWidget) {
|
||||
NS_WARNING("Can't find parent for QFileDialog");
|
||||
}
|
||||
|
||||
nsAutoString str(title);
|
||||
mDialog = new QFileDialog(parentWidget, QString::fromUtf16(str.get()));
|
||||
|
||||
nsAutoString str(aTitle);
|
||||
mCaption = QString::fromUtf16(str.get());
|
||||
mParent = aParent;
|
||||
mMode = mode;
|
||||
}
|
||||
|
@ -40,16 +40,10 @@
|
||||
#ifndef NSFILEPICKER_H
|
||||
#define NSFILEPICKER_H
|
||||
|
||||
#include <qfiledialog.h>
|
||||
#include <qpointer.h>
|
||||
#include <QPointer>
|
||||
#include "nsBaseFilePicker.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsCOMArray.h"
|
||||
|
||||
class nsIWidget;
|
||||
class nsILocalFile;
|
||||
class QFileDialog;
|
||||
|
||||
class nsFilePicker : public nsBaseFilePicker
|
||||
@ -60,19 +54,19 @@ public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFilePicker (less what's in nsBaseFilePicker)
|
||||
NS_IMETHODIMP Init(nsIDOMWindow *parent, const nsAString & title, PRInt16 mode);
|
||||
NS_IMETHODIMP Init(nsIDOMWindow* parent, const nsAString& title, PRInt16 mode);
|
||||
NS_IMETHODIMP AppendFilters(PRInt32 filterMask);
|
||||
NS_IMETHODIMP AppendFilter(const nsAString & aTitle, const nsAString & aFilter);
|
||||
NS_IMETHODIMP GetDefaultString(nsAString & aDefaultString);
|
||||
NS_IMETHODIMP SetDefaultString(const nsAString & aDefaultString);
|
||||
NS_IMETHODIMP GetDefaultExtension(nsAString & aDefaultExtension);
|
||||
NS_IMETHODIMP SetDefaultExtension(const nsAString & aDefaultExtension);
|
||||
NS_IMETHODIMP GetFilterIndex(PRInt32 *aFilterIndex);
|
||||
NS_IMETHODIMP AppendFilter(const nsAString& aTitle, const nsAString& aFilter);
|
||||
NS_IMETHODIMP GetDefaultString(nsAString& aDefaultString);
|
||||
NS_IMETHODIMP SetDefaultString(const nsAString& aDefaultString);
|
||||
NS_IMETHODIMP GetDefaultExtension(nsAString& aDefaultExtension);
|
||||
NS_IMETHODIMP SetDefaultExtension(const nsAString& aDefaultExtension);
|
||||
NS_IMETHODIMP GetFilterIndex(PRInt32* aFilterIndex);
|
||||
NS_IMETHODIMP SetFilterIndex(PRInt32 aFilterIndex);
|
||||
NS_IMETHODIMP GetFile(nsILocalFile * *aFile);
|
||||
NS_IMETHODIMP GetFileURL(nsIURI * *aFileURL);
|
||||
NS_IMETHODIMP GetFiles(nsISimpleEnumerator * *aFiles);
|
||||
NS_IMETHODIMP Show(PRInt16 *aReturn);
|
||||
NS_IMETHODIMP GetFile(nsILocalFile* *aFile);
|
||||
NS_IMETHODIMP GetFileURL(nsIURI* *aFileURL);
|
||||
NS_IMETHODIMP GetFiles(nsISimpleEnumerator* *aFiles);
|
||||
NS_IMETHODIMP Show(PRInt16* aReturn);
|
||||
|
||||
private:
|
||||
~nsFilePicker();
|
||||
@ -91,6 +85,9 @@ protected:
|
||||
|
||||
nsTArray<nsCString> mFilters;
|
||||
nsTArray<nsCString> mFilterNames;
|
||||
|
||||
QString mCaption;
|
||||
nsIWidget* mParent;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // NSFILEPICKER_H
|
||||
|
317
widget/src/qt/nsMFilePicker.cpp
Normal file
317
widget/src/qt/nsMFilePicker.cpp
Normal file
@ -0,0 +1,317 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=4 et :
|
||||
*/
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* The Mozilla Foundation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Oleg Romashin <romaxa@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
||||
#include <QWidget>
|
||||
#include "nsMFilePicker.h"
|
||||
|
||||
|
||||
// Use Qt Tracker API to get attachment data from tracker:
|
||||
#include <QtSparql/QSparqlConnection>
|
||||
#include <QtSparql/QSparqlQuery>
|
||||
#include <QtSparql/QSparqlResult>
|
||||
|
||||
#include <MApplication>
|
||||
#include <MApplicationPage>
|
||||
#include <MApplicationWindow>
|
||||
#include <MSceneManager>
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QPointer>
|
||||
|
||||
#include <SelectSingleContentItemPage.h>
|
||||
#include <SelectMultipleContentItemsPage.h>
|
||||
|
||||
MeegoFileDialog::MeegoFileDialog(QObject* aParent)
|
||||
: QObject(aParent)
|
||||
, mMode(Mode_Unknown)
|
||||
{
|
||||
}
|
||||
|
||||
MeegoFileDialog::~MeegoFileDialog()
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
MeegoFileDialog::exec()
|
||||
{
|
||||
MApplicationPage* page = NULL;
|
||||
switch(mMode) {
|
||||
case Mode_OpenFile:
|
||||
page = createOpenFilePage();
|
||||
break;
|
||||
case Mode_OpenFiles:
|
||||
page = createOpenFilesPage();
|
||||
break;
|
||||
case Mode_OpenDirectory:
|
||||
page = createOpenDirectoryPage();
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
page->setTitle(mCaption);
|
||||
|
||||
QPointer<MApplicationWindow> appWindow = new MApplicationWindow(MApplication::activeWindow());
|
||||
QObject::connect(MApplication::activeWindow(), SIGNAL(switcherEntered()), this, SLOT(backButtonClicked()));
|
||||
appWindow->show();
|
||||
|
||||
// a not so pretty Hack to build up a back button
|
||||
// by using a empty scene window for a pseudo history stack
|
||||
MSceneWindow* fakeWindow = new MSceneWindow();
|
||||
// tell fake window to disappear when page back was clicked.
|
||||
connect(page, SIGNAL(backButtonClicked()), fakeWindow, SLOT(disappear()));
|
||||
// let new page appear on pseudo Application Window
|
||||
appWindow->sceneManager()->appearSceneWindowNow(page);
|
||||
|
||||
// get, manipulate and set history stack
|
||||
QList<MSceneWindow*> sceneWindowHistory = appWindow->sceneManager()->pageHistory();
|
||||
sceneWindowHistory.insert(0, fakeWindow);
|
||||
appWindow->sceneManager()->setPageHistory(sceneWindowHistory);
|
||||
|
||||
// start own eventloop
|
||||
QEventLoop eventLoop;
|
||||
mEventLoop = &eventLoop;
|
||||
QPointer<MeegoFileDialog> guard = this;
|
||||
(void) eventLoop.exec(QEventLoop::DialogExec);
|
||||
if (guard.isNull()) {
|
||||
return 0;
|
||||
}
|
||||
if (page) {
|
||||
page->disappear();
|
||||
delete page;
|
||||
}
|
||||
if (appWindow) {
|
||||
delete appWindow;
|
||||
}
|
||||
mEventLoop = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
MApplicationPage*
|
||||
MeegoFileDialog::createOpenFilePage()
|
||||
{
|
||||
QStringList itemType("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#FileDataObject");
|
||||
|
||||
SelectSingleContentItemPage* page =
|
||||
new SelectSingleContentItemPage(QString(),
|
||||
itemType);
|
||||
|
||||
connect(page, SIGNAL(contentItemSelected(const QString&)),
|
||||
this, SLOT (contentItemSelected(const QString&)));
|
||||
|
||||
connect(page, SIGNAL(backButtonClicked()),
|
||||
this, SLOT (backButtonClicked()));
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
MApplicationPage*
|
||||
MeegoFileDialog::createOpenFilesPage()
|
||||
{
|
||||
QStringList itemType("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Folder");
|
||||
|
||||
SelectMultipleContentItemsPage* page = new SelectMultipleContentItemsPage(QString(), itemType);
|
||||
connect(page, SIGNAL(contentItemsSelected(const QStringList&)),
|
||||
this, SLOT (contentItemsSelected(const QStringList&)));
|
||||
|
||||
connect(page, SIGNAL(backButtonClicked()),
|
||||
this, SLOT (backButtonClicked()));
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
MApplicationPage*
|
||||
MeegoFileDialog::createOpenDirectoryPage()
|
||||
{
|
||||
QStringList itemType("http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Folder");
|
||||
|
||||
SelectSingleContentItemPage* page = new SelectSingleContentItemPage(QString(), itemType);
|
||||
connect(page, SIGNAL(contentItemSelected(const QString&)),
|
||||
this, SLOT (contentItemSelected(const QString&)));
|
||||
|
||||
connect(page, SIGNAL(backButtonClicked()),
|
||||
this, SLOT (backButtonClicked()));
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
QStringList
|
||||
MeegoFileDialog::selectedFileNames() const
|
||||
{
|
||||
return mSelectedFileNames;
|
||||
}
|
||||
|
||||
bool
|
||||
MeegoFileDialog::hasSelectedFileNames() const
|
||||
{
|
||||
return !mSelectedFileNames.isEmpty();
|
||||
}
|
||||
|
||||
void
|
||||
MeegoFileDialog::contentItemSelected(const QString& aContentItem)
|
||||
{
|
||||
mSelectedFileNames.clear();
|
||||
|
||||
if (aContentItem.isEmpty()) {
|
||||
finishEventLoop();
|
||||
return;
|
||||
}
|
||||
|
||||
QUrl fileUrl = trackerIdToFilename(aContentItem);
|
||||
QFileInfo fileInfo(fileUrl.toLocalFile());
|
||||
if (fileInfo.isFile()) {
|
||||
mSelectedFileNames << fileInfo.canonicalFilePath();
|
||||
}
|
||||
|
||||
finishEventLoop();
|
||||
}
|
||||
|
||||
void
|
||||
MeegoFileDialog::contentItemsSelected(const QStringList& aContentItems)
|
||||
{
|
||||
mSelectedFileNames.clear();
|
||||
|
||||
foreach (QString contentItem, aContentItems) {
|
||||
QUrl fileUrl = trackerIdToFilename(contentItem);
|
||||
QFileInfo fileInfo(fileUrl.toLocalFile());
|
||||
if (fileInfo.isFile()) {
|
||||
mSelectedFileNames << fileInfo.canonicalFilePath();
|
||||
}
|
||||
}
|
||||
|
||||
finishEventLoop();
|
||||
}
|
||||
|
||||
void
|
||||
MeegoFileDialog::backButtonClicked()
|
||||
{
|
||||
mSelectedFileNames.clear();
|
||||
finishEventLoop();
|
||||
}
|
||||
|
||||
/* static */ QString
|
||||
MeegoFileDialog::getOpenFileName(QWidget* parent,
|
||||
const QString& caption,
|
||||
const QString& dir,
|
||||
const QString& filter)
|
||||
{
|
||||
QPointer<MeegoFileDialog> picker = new MeegoFileDialog(parent);
|
||||
|
||||
QString result;
|
||||
picker->mMode = MeegoFileDialog::Mode_OpenFile;
|
||||
picker->mCaption = caption;
|
||||
picker->exec();
|
||||
|
||||
// Need separate 'if' because picker might have been destroyed by its parent during exec()
|
||||
if (picker) {
|
||||
if (picker->hasSelectedFileNames()) {
|
||||
result = picker->selectedFileNames().first();
|
||||
}
|
||||
delete picker;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* static */ QString
|
||||
MeegoFileDialog::getExistingDirectory(QWidget* parent,const QString& caption, const QString& dir)
|
||||
{
|
||||
QPointer<MeegoFileDialog> picker = new MeegoFileDialog(parent);
|
||||
|
||||
QString result;
|
||||
picker->mMode = MeegoFileDialog::Mode_OpenDirectory;
|
||||
picker->mCaption = caption;
|
||||
picker->exec();
|
||||
|
||||
// Need separate 'if' because picker might have been destroyed by its parent during exec()
|
||||
if (picker) {
|
||||
if (picker->hasSelectedFileNames()) {
|
||||
result = picker->selectedFileNames().first();
|
||||
}
|
||||
delete picker;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* static */ QStringList
|
||||
MeegoFileDialog::getOpenFileNames(QWidget* parent,
|
||||
const QString& caption,
|
||||
const QString& dir,
|
||||
const QString& filter)
|
||||
{
|
||||
QPointer<MeegoFileDialog> picker = new MeegoFileDialog(parent);
|
||||
|
||||
QStringList result;
|
||||
picker->mMode = MeegoFileDialog::Mode_OpenFiles;
|
||||
picker->mCaption = caption;
|
||||
picker->exec();
|
||||
|
||||
// Need separate 'if' because picker might have been destroyed by its parent during exec()
|
||||
if (picker) {
|
||||
if (picker->hasSelectedFileNames()) {
|
||||
result = picker->selectedFileNames();
|
||||
}
|
||||
delete picker;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QUrl
|
||||
MeegoFileDialog::trackerIdToFilename(const QString& trackerId)
|
||||
{
|
||||
QSparqlQuery query("SELECT ?u WHERE { ?:tUri nie:url ?u . }");
|
||||
query.bindValue("tUri", QUrl(trackerId)); // That puts <trackerId> into the query
|
||||
QSparqlConnection connection("QTRACKER"); // Exact string needed to make connection to tracker
|
||||
QSparqlResult* result = connection.exec(query);
|
||||
|
||||
result->waitForFinished();
|
||||
result->first();
|
||||
|
||||
QUrl resultFile;
|
||||
if (result->isValid()) {
|
||||
resultFile = QUrl(result->binding(0).value().toString());
|
||||
}
|
||||
delete result;
|
||||
|
||||
return resultFile;
|
||||
}
|
99
widget/src/qt/nsMFilePicker.h
Normal file
99
widget/src/qt/nsMFilePicker.h
Normal file
@ -0,0 +1,99 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: sw=2 ts=4 et :
|
||||
*/
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* The Mozilla Foundation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Oleg Romashin <romaxa@gmail.com>
|
||||
* Stefan Hundhammer <HuHa-zilla@gmx.de>
|
||||
* Jeremias Bosch <jeremias.bosch@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef NSMFILEDIALOG_H
|
||||
#define NSMFILEDIALOG_H
|
||||
|
||||
#include <QEventLoop>
|
||||
#include <QStringList>
|
||||
#include <QUrl>
|
||||
|
||||
class MApplicationPage;
|
||||
class MeegoFileDialog : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
enum MeegoFileDialogMode {
|
||||
Mode_Unknown = -1,
|
||||
Mode_OpenFile = 0,
|
||||
Mode_OpenFiles = 1,
|
||||
Mode_OpenDirectory = 2
|
||||
// No Mode_SaveFile - the content picker can't handle that
|
||||
};
|
||||
|
||||
MeegoFileDialog(QObject* aParent = 0);
|
||||
virtual ~MeegoFileDialog();
|
||||
|
||||
QStringList selectedFileNames() const;
|
||||
bool hasSelectedFileNames() const;
|
||||
|
||||
static QString getOpenFileName(QWidget* parent, const QString &caption, const QString& dir, const QString& filter);
|
||||
static QStringList getOpenFileNames(QWidget* parent, const QString& caption, const QString& dir, const QString& filter);
|
||||
static QString getExistingDirectory(QWidget* parent, const QString& caption, const QString& dir);
|
||||
|
||||
int exec();
|
||||
|
||||
private slots:
|
||||
void contentItemSelected(const QString& aItem);
|
||||
void contentItemsSelected(const QStringList& aItems);
|
||||
void backButtonClicked();
|
||||
|
||||
private:
|
||||
QUrl trackerIdToFilename(const QString& trackerId);
|
||||
MApplicationPage* createOpenFilePage();
|
||||
MApplicationPage* createOpenFilesPage();
|
||||
MApplicationPage* createOpenDirectoryPage();
|
||||
void finishEventLoop() {
|
||||
if (!mEventLoop)
|
||||
return;
|
||||
mEventLoop->exit(0);
|
||||
mEventLoop = 0;
|
||||
}
|
||||
|
||||
QEventLoop* mEventLoop;
|
||||
MeegoFileDialogMode mMode;
|
||||
QString mCaption;
|
||||
QStringList mSelectedFileNames;
|
||||
};
|
||||
|
||||
#endif // NSMFILEDIALOG_H
|
Loading…
Reference in New Issue
Block a user