Commit acd5feaf authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Fixes: React to desktop file manager drop events.

Task: 238143
parent 8f03874b
......@@ -77,6 +77,7 @@
#include <QtCore/QSettings>
#include <QtCore/QTimer>
#include <QtCore/QtPlugin>
#include <QtCore/QUrl>
#include <QtGui/QApplication>
#include <QtGui/QCloseEvent>
......@@ -103,10 +104,9 @@ extern "C" void handleSigInt(int sig)
using namespace Core;
using namespace Core::Internal;
namespace {
enum { debugMainWindow = 0 };
}
static const char *uriListMimeFormatC = "text/uri-list";
enum { debugMainWindow = 0 };
MainWindow::MainWindow() :
QMainWindow(),
......@@ -157,15 +157,15 @@ MainWindow::MainWindow() :
QCoreApplication::setOrganizationName(QLatin1String("Nokia"));
QSettings::setDefaultFormat(QSettings::IniFormat);
QString baseName = qApp->style()->objectName();
#ifdef Q_WS_X11
if (baseName == "windows") {
#ifdef Q_WS_X11
if (baseName == QLatin1String("windows")) {
// Sometimes we get the standard windows 95 style as a fallback
// e.g. if we are running on a KDE4 desktop
QByteArray desktopEnvironment = qgetenv("DESKTOP_SESSION");
if (desktopEnvironment == "kde")
baseName = "plastique";
baseName = QLatin1String("plastique");
else
baseName = "cleanlooks";
baseName = QLatin1String("cleanlooks");
}
#endif
qApp->setStyle(new ManhattanStyle(baseName));
......@@ -202,6 +202,7 @@ MainWindow::MainWindow() :
#endif
statusBar()->setProperty("p_styled", true);
setAcceptDrops(true);
}
void MainWindow::setSidebarVisible(bool visible)
......@@ -361,6 +362,55 @@ void MainWindow::closeEvent(QCloseEvent *event)
event->accept();
}
// Check for desktop file manager file drop events
static bool isDesktopFileManagerDrop(const QMimeData *d, QStringList *files = 0)
{
if (files)
files->clear();
// Extract dropped files from Mime data.
if (!d->hasFormat(QLatin1String(uriListMimeFormatC)))
return false;
const QList<QUrl> urls = d->urls();
if (urls.empty())
return false;
// Try to find local files
bool hasFiles = false;
const QList<QUrl>::const_iterator cend = urls.constEnd();
for (QList<QUrl>::const_iterator it = urls.constBegin(); it != cend; ++it) {
const QString fileName = it->toLocalFile();
if (!fileName.isEmpty()) {
hasFiles = true;
if (files) {
files->push_back(fileName);
} else {
break; // No result list, sufficient for checking
}
}
}
return hasFiles;
}
void MainWindow::dragEnterEvent(QDragEnterEvent *event)
{
if (isDesktopFileManagerDrop(event->mimeData())) {
event->accept();
} else {
event->ignore();
}
}
void MainWindow::dropEvent(QDropEvent *event)
{
QStringList files;
if (isDesktopFileManagerDrop(event->mimeData(), &files)) {
event->accept();
openFiles(files);
} else {
event->ignore();
}
}
IContext *MainWindow::currentContextObject() const
{
return m_activeContext;
......
......@@ -139,8 +139,10 @@ public slots:
void showOptionsDialog(const QString &category = QString(), const QString &page = QString());
protected:
void changeEvent(QEvent *e);
void closeEvent(QCloseEvent *event);
virtual void changeEvent(QEvent *e);
virtual void closeEvent(QCloseEvent *event);
virtual void dragEnterEvent(QDragEnterEvent *event);
virtual void dropEvent(QDropEvent *event);
private slots:
void openFile();
......
......@@ -150,6 +150,7 @@ WelcomeMode::WelcomeMode() :
updateWelcomePage(welcomePageData);
l->addWidget(m_d->m_webview);
m_d->m_webview->setAcceptDrops(false);
#else
m_d->m_label->setWordWrap(true);
......
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