diff options
author | Eike Ziller <eike.ziller@digia.com> | 2014-07-11 16:08:17 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@digia.com> | 2014-07-11 16:08:27 +0200 |
commit | 04fdbb0e215544358cf313cbc3c866156fea7ddd (patch) | |
tree | c9ace7deecb673af90b5f03435818e80a651111c /src/libs/utils | |
parent | b4248baff01a8e584b0beea90b3d286af2368efe (diff) | |
parent | 18429ff390d6808c4d1fe43ef1ec460c70e2fa50 (diff) | |
download | qt-creator-04fdbb0e215544358cf313cbc3c866156fea7ddd.tar.gz |
Merge remote-tracking branch 'origin/3.2'
Change-Id: Ifa095e8503bc9bf47389d34251301cae67a944f8
Diffstat (limited to 'src/libs/utils')
-rw-r--r-- | src/libs/utils/fileutils.cpp | 71 | ||||
-rw-r--r-- | src/libs/utils/fileutils.h | 21 | ||||
-rw-r--r-- | src/libs/utils/proxycredentialsdialog.cpp | 81 | ||||
-rw-r--r-- | src/libs/utils/proxycredentialsdialog.h | 63 | ||||
-rw-r--r-- | src/libs/utils/proxycredentialsdialog.ui | 106 | ||||
-rw-r--r-- | src/libs/utils/utils-lib.pri | 9 | ||||
-rw-r--r-- | src/libs/utils/utils.qbs | 3 |
7 files changed, 351 insertions, 3 deletions
diff --git a/src/libs/utils/fileutils.cpp b/src/libs/utils/fileutils.cpp index 52aafce6dc..4993f99a48 100644 --- a/src/libs/utils/fileutils.cpp +++ b/src/libs/utils/fileutils.cpp @@ -36,7 +36,12 @@ #include <QDir> #include <QDebug> #include <QDateTime> +#include <QDragEnterEvent> +#include <QDropEvent> #include <QMessageBox> +#include <QMimeData> +#include <QTimer> +#include <QUrl> #ifdef Q_OS_WIN #include <qt_windows.h> @@ -679,6 +684,72 @@ FileName &FileName::appendString(QChar str) return *this; } +static bool isDesktopFileManagerDrop(const QMimeData *d, QStringList *files = 0) +{ + if (files) + files->clear(); + // Extract dropped files from Mime data. + if (!d->hasUrls()) + 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; +} + +FileDropSupport::FileDropSupport(QWidget *parentWidget) + : QObject(parentWidget) +{ + QTC_ASSERT(parentWidget, return); + parentWidget->setAcceptDrops(true); + parentWidget->installEventFilter(this); +} + +bool FileDropSupport::eventFilter(QObject *obj, QEvent *event) +{ + Q_UNUSED(obj) + if (event->type() == QEvent::DragEnter) { + auto dee = static_cast<QDragEnterEvent *>(event); + if (isDesktopFileManagerDrop(dee->mimeData())) + event->accept(); + else + event->ignore(); + } else if (event->type() == QEvent::Drop) { + auto de = static_cast<QDropEvent *>(event); + QStringList tempFiles; + if (isDesktopFileManagerDrop(de->mimeData(), &tempFiles)) { + event->accept(); + bool needToScheduleEmit = m_files.isEmpty(); + m_files.append(tempFiles); + if (needToScheduleEmit) // otherwise we already have a timer pending + QTimer::singleShot(0, this, SLOT(emitFilesDropped())); + } else { + event->ignore(); + } + } + return false; +} + +void FileDropSupport::emitFilesDropped() +{ + QTC_ASSERT(!m_files.isEmpty(), return); + emit filesDropped(m_files); + m_files.clear(); +} + } // namespace Utils QT_BEGIN_NAMESPACE diff --git a/src/libs/utils/fileutils.h b/src/libs/utils/fileutils.h index 414e72095d..b2dbd66ac1 100644 --- a/src/libs/utils/fileutils.h +++ b/src/libs/utils/fileutils.h @@ -35,6 +35,7 @@ #include <QCoreApplication> #include <QXmlStreamWriter> // Mac. #include <QMetaType> +#include <QStringList> namespace Utils {class FileName; } @@ -192,6 +193,26 @@ private: bool m_autoRemove; }; +class QTCREATOR_UTILS_EXPORT FileDropSupport : public QObject +{ + Q_OBJECT +public: + FileDropSupport(QWidget *parentWidget); + +signals: + void filesDropped(const QStringList &files); + +protected: + bool eventFilter(QObject *obj, QEvent *event); + +private slots: + void emitFilesDropped(); + +private: + QStringList m_files; + +}; + } // namespace Utils QT_BEGIN_NAMESPACE diff --git a/src/libs/utils/proxycredentialsdialog.cpp b/src/libs/utils/proxycredentialsdialog.cpp new file mode 100644 index 0000000000..848dc68def --- /dev/null +++ b/src/libs/utils/proxycredentialsdialog.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "proxycredentialsdialog.h" +#include "ui_proxycredentialsdialog.h" + +#include <utils/networkaccessmanager.h> +#include <QNetworkProxy> + +using namespace Utils; + +/*! + \class Utils::ProxyCredentialsDialog + + Dialog for asking the user about proxy credentials (username, password). +*/ + +ProxyCredentialsDialog::ProxyCredentialsDialog(const QNetworkProxy &proxy, QWidget *parent) : + QDialog(parent), + ui(new Ui::ProxyCredentialsDialog) +{ + ui->setupUi(this); + + setUserName(proxy.user()); + setPassword(proxy.password()); + + const QString proxyString = QString::fromLatin1("%1:%2").arg(proxy.hostName()).arg(proxy.port()); + ui->infotext->setText(ui->infotext->text().arg(proxyString)); +} + +ProxyCredentialsDialog::~ProxyCredentialsDialog() +{ + delete ui; +} + +QString ProxyCredentialsDialog::userName() const +{ + return ui->usernameLineEdit->text(); +} + +void ProxyCredentialsDialog::setUserName(const QString &username) +{ + ui->usernameLineEdit->setText(username); +} + +QString ProxyCredentialsDialog::password() const +{ + return ui->passwordLineEdit->text(); +} + +void ProxyCredentialsDialog::setPassword(const QString &passwd) +{ + ui->passwordLineEdit->setText(passwd); +} + diff --git a/src/libs/utils/proxycredentialsdialog.h b/src/libs/utils/proxycredentialsdialog.h new file mode 100644 index 0000000000..cea025888d --- /dev/null +++ b/src/libs/utils/proxycredentialsdialog.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef PROXYCREDENTIALSDIALOG_H +#define PROXYCREDENTIALSDIALOG_H + +#include "utils_global.h" +#include <QDialog> + +QT_FORWARD_DECLARE_CLASS(QNetworkProxy) + +namespace Utils { + +namespace Ui { +class ProxyCredentialsDialog; +} + +class QTCREATOR_UTILS_EXPORT ProxyCredentialsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit ProxyCredentialsDialog(const QNetworkProxy &proxy, QWidget *parent = 0); + ~ProxyCredentialsDialog(); + + QString userName() const; + void setUserName(const QString &username); + QString password() const; + void setPassword(const QString &passwd); + +private: + Ui::ProxyCredentialsDialog *ui; +}; + +} // namespace Utils + +#endif // PROXYCREDENTIALSDIALOG_H diff --git a/src/libs/utils/proxycredentialsdialog.ui b/src/libs/utils/proxycredentialsdialog.ui new file mode 100644 index 0000000000..4bf6a17c33 --- /dev/null +++ b/src/libs/utils/proxycredentialsdialog.ui @@ -0,0 +1,106 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Utils::ProxyCredentialsDialog</class> + <widget class="QDialog" name="Utils::ProxyCredentialsDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>279</width> + <height>114</height> + </rect> + </property> + <property name="windowTitle"> + <string>Proxy Credentials</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QLabel" name="infotext"> + <property name="text"> + <string>The proxy %1 requires a username and password.</string> + </property> + </widget> + </item> + <item> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="usernameLabel"> + <property name="text"> + <string>Username:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="usernameLineEdit"> + <property name="placeholderText"> + <string>Username</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="passwordLabel"> + <property name="text"> + <string>Password:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="passwordLineEdit"> + <property name="echoMode"> + <enum>QLineEdit::Password</enum> + </property> + <property name="placeholderText"> + <string>Password</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>Utils::ProxyCredentialsDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>Utils::ProxyCredentialsDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index be12d23f98..0532576a59 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -89,7 +89,8 @@ SOURCES += $$PWD/environment.cpp \ $$PWD/completinglineedit.cpp \ $$PWD/winutils.cpp \ $$PWD/itemviews.cpp \ - $$PWD/treeviewcombobox.cpp + $$PWD/treeviewcombobox.cpp \ + $$PWD/proxycredentialsdialog.cpp win32:SOURCES += $$PWD/consoleprocess_win.cpp else:SOURCES += $$PWD/consoleprocess_unix.cpp @@ -185,10 +186,12 @@ HEADERS += \ $$PWD/treeviewcombobox.h \ $$PWD/scopedswap.h \ $$PWD/algorithm.h \ - $$PWD/QtConcurrentTools + $$PWD/QtConcurrentTools \ + $$PWD/proxycredentialsdialog.h FORMS += $$PWD/filewizardpage.ui \ $$PWD/projectintropage.ui \ - $$PWD/newclasswidget.ui + $$PWD/newclasswidget.ui \ + $$PWD/proxycredentialsdialog.ui RESOURCES += $$PWD/utils.qrc diff --git a/src/libs/utils/utils.qbs b/src/libs/utils/utils.qbs index 6a17f6bcc9..be6094d1d7 100644 --- a/src/libs/utils/utils.qbs +++ b/src/libs/utils/utils.qbs @@ -136,6 +136,9 @@ QtcLibrary { "projectnamevalidatinglineedit.h", "proxyaction.cpp", "proxyaction.h", + "proxycredentialsdialog.cpp", + "proxycredentialsdialog.h", + "proxycredentialsdialog.ui", "qtcassert.cpp", "qtcassert.h", "qtcolorbutton.cpp", |