Commit 76a66d02 authored by shibakaneki's avatar shibakaneki

Drag and drop support from Safari done

parent 6e80911b
...@@ -1886,6 +1886,19 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint ...@@ -1886,6 +1886,19 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint
if("" != pMimeData->text()){ if("" != pMimeData->text()){
mActiveScene->addText(pMimeData->text(), pPos); mActiveScene->addText(pMimeData->text(), pPos);
} }
else{
#ifdef Q_WS_MACX
// With Safari, in 95% of the drops, the mime datas are hidden in Apple Web Archive pasteboard type.
// This is due to the way Safari is working so we have to dig into the pasteboard in order to retrieve
// the data.
QString qsUrl = UBPlatformUtils::urlFromClipboard();
if("" != qsUrl){
// We finally got the url of the dropped ressource! Let's import it!
downloadURL(qsUrl, pPos);
return;
}
#endif
}
} }
} }
......
...@@ -98,36 +98,23 @@ class UBPlatformUtils ...@@ -98,36 +98,23 @@ class UBPlatformUtils
public: public:
static void init(); static void init();
static void destroy(); static void destroy();
static QString applicationResourcesDirectory(); static QString applicationResourcesDirectory();
static void hideFile(const QString &filePath); static void hideFile(const QString &filePath);
static void setFileType(const QString &filePath, unsigned long fileType); static void setFileType(const QString &filePath, unsigned long fileType);
static void fadeDisplayOut(); static void fadeDisplayOut();
static void fadeDisplayIn(); static void fadeDisplayIn();
static QString preferredTranslation(); static QString preferredTranslation();
static QString preferredLanguage(); static QString preferredLanguage();
static bool hasVirtualKeyboard(); static bool hasVirtualKeyboard();
//static void showVirtualKeyboard(); //static void showVirtualKeyboard();
static void runInstaller(const QString &installerFilePath); static void runInstaller(const QString &installerFilePath);
static void bringPreviousProcessToFront(); static void bringPreviousProcessToFront();
static QString osUserLoginName(); static QString osUserLoginName();
static void setDesktopMode(bool desktop); static void setDesktopMode(bool desktop);
static void setWindowNonActivableFlag(QWidget* widget, bool nonAcivable); static void setWindowNonActivableFlag(QWidget* widget, bool nonAcivable);
static QString computerName(); static QString computerName();
static UBKeyboardLocale** getKeyboardLayouts(int& nCount); static UBKeyboardLocale** getKeyboardLayouts(int& nCount);
static QString urlFromClipboard();
}; };
......
...@@ -331,3 +331,12 @@ void UBPlatformUtils::destroyKeyboardLayouts() ...@@ -331,3 +331,12 @@ void UBPlatformUtils::destroyKeyboardLayouts()
delete [] keyboardLayouts; delete [] keyboardLayouts;
keyboardLayouts = NULL; keyboardLayouts = NULL;
} }
QString UBPlatformUtils::urlFromClipboard()
{
QString qsRet;
// Not used on Linux
return qsRet;
}
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#import <Foundation/NSAutoreleasePool.h> #import <Foundation/NSAutoreleasePool.h>
#import <Carbon/Carbon.h> #import <Carbon/Carbon.h>
#import <APELite.h> #import <APELite.h>
#import <WebKit/WebKit.h>
#import <AppKit/AppKit.h>
NSString* bundleShortVersion(NSBundle *bundle) NSString* bundleShortVersion(NSBundle *bundle)
...@@ -537,3 +539,17 @@ void UBPlatformUtils::initializeKeyboardLayouts() ...@@ -537,3 +539,17 @@ void UBPlatformUtils::initializeKeyboardLayouts()
void UBPlatformUtils::destroyKeyboardLayouts() void UBPlatformUtils::destroyKeyboardLayouts()
{} {}
QString UBPlatformUtils::urlFromClipboard()
{
QString qsRet;
NSPasteboard* pPasteboard = [NSPasteboard pasteboardWithName:@"Apple CFPasteboard drag"];
WebArchive* pArchive = [[WebArchive alloc] initWithData:[pPasteboard dataForType:@"com.apple.webarchive"]];
qsRet = [[[[pArchive mainResource] URL] absoluteString] UTF8String];
[pArchive release];
return qsRet;
}
...@@ -368,3 +368,10 @@ void UBPlatformUtils::destroyKeyboardLayouts() ...@@ -368,3 +368,10 @@ void UBPlatformUtils::destroyKeyboardLayouts()
delete [] keyboardLayouts; delete [] keyboardLayouts;
keyboardLayouts = NULL; keyboardLayouts = NULL;
} }
QString UBPlatformUtils::urlFromClipboard()
{
QString qsRet;
// Not implemented yet
return qsRet;
}
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "core/UBDownloadManager.h" #include "core/UBDownloadManager.h"
#include "frameworks/UBFileSystemUtils.h" #include "frameworks/UBFileSystemUtils.h"
#include "frameworks/UBPlatformUtils.h"
#include "core/memcheck.h" #include "core/memcheck.h"
...@@ -389,6 +390,19 @@ void UBLibraryWidget::dropEvent(QDropEvent *event) ...@@ -389,6 +390,19 @@ void UBLibraryWidget::dropEvent(QDropEvent *event)
mLibraryController->importItemOnLibrary(filePath); mLibraryController->importItemOnLibrary(filePath);
bDropAccepted = true; bDropAccepted = true;
} }
else{
#ifdef Q_WS_MACX
// With Safari, in 95% of the drops, the mime datas are hidden in Apple Web Archive pasteboard type.
// This is due to the way Safari is working so we have to dig into the pasteboard in order to retrieve
// the data.
QString qsUrl = UBPlatformUtils::urlFromClipboard();
if("" != qsUrl){
// We finally got the url of the dropped ressource! Let's import it!
mLibraryController->importItemOnLibrary(qsUrl);
bDropAccepted = true;
}
#endif
}
} }
else if (pMimeData->hasImage()){ else if (pMimeData->hasImage()){
qDebug() << "hasImage"; qDebug() << "hasImage";
......
...@@ -79,6 +79,7 @@ private: ...@@ -79,6 +79,7 @@ private:
void refreshView(); void refreshView();
void generateItems(); void generateItems();
void appendChainedElement(UBChainedLibElement* element, UBChainedLibElement* toElem); void appendChainedElement(UBChainedLibElement* element, UBChainedLibElement* toElem);
UBLibElement* elementAt(QPoint p); UBLibElement* elementAt(QPoint p);
UBLibElement* elementFromFilePath(const QString& filePath); UBLibElement* elementFromFilePath(const QString& filePath);
UBLibraryController* mLibraryController; UBLibraryController* mLibraryController;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment