diff options
Diffstat (limited to 'src/views')
| -rw-r--r-- | src/views/dolphinremoteencoding.cpp | 5 | ||||
| -rw-r--r-- | src/views/dolphinview.cpp | 32 | ||||
| -rw-r--r-- | src/views/dolphinview.h | 13 | ||||
| -rw-r--r-- | src/views/draganddrophelper.cpp | 16 | ||||
| -rw-r--r-- | src/views/draganddrophelper.h | 11 | ||||
| -rw-r--r-- | src/views/versioncontrol/updateitemstatesthread.cpp | 26 | ||||
| -rw-r--r-- | src/views/versioncontrol/updateitemstatesthread.h | 9 | ||||
| -rw-r--r-- | src/views/versioncontrol/versioncontrolobserver.cpp | 34 |
8 files changed, 55 insertions, 91 deletions
diff --git a/src/views/dolphinremoteencoding.cpp b/src/views/dolphinremoteencoding.cpp index 375b3fd46..04b350eda 100644 --- a/src/views/dolphinremoteencoding.cpp +++ b/src/views/dolphinremoteencoding.cpp @@ -38,7 +38,6 @@ #include <KMenu> #include <KProtocolInfo> #include <KProtocolManager> -#include <KIO/SlaveConfig> #include <KIO/Scheduler> #include <KConfigGroup> @@ -132,9 +131,7 @@ void DolphinRemoteEncoding::updateMenu() m_menu->menu()->actions().at(i)->setChecked(false); } - QString charset = KGlobal::charsets()->descriptionForEncoding(KIO::SlaveConfig::self()->configData(m_currentURL.protocol(), - m_currentURL.host(), DATA_KEY)); - + const QString charset = KGlobal::charsets()->descriptionForEncoding(KProtocolManager::charsetFor(m_currentURL)); if (!charset.isEmpty()) { int id = 0; bool isFound = false; diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 502ffd428..d1e154f68 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -1023,14 +1023,16 @@ void DolphinView::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* even event->buttons(), event->modifiers()); - const QString error = DragAndDropHelper::dropUrls(destItem, destUrl, &dropEvent); + QString error; + KonqOperations* op = DragAndDropHelper::dropUrls(destItem, destUrl, &dropEvent, error); if (!error.isEmpty()) { emit infoMessage(error); } - if (destUrl == url()) { + if (op && destUrl == url()) { // Mark the dropped urls as selected. - markPastedUrlsAsSelected(event->mimeData()); + m_clearSelectionBeforeSelectingNewItems = true; + connect(op, SIGNAL(urlPasted(KUrl)), this, SLOT(slotUrlPasted(KUrl))); } } @@ -1066,6 +1068,11 @@ void DolphinView::slotMouseButtonPressed(int itemIndex, Qt::MouseButtons buttons } } +void DolphinView::slotAboutToCreate(const KUrl::List& urls) +{ + m_selectedUrls << urls; +} + void DolphinView::slotSelectionChanged(const QSet<int>& current, const QSet<int>& previous) { const int currentCount = current.count(); @@ -1523,8 +1530,11 @@ void DolphinView::applyModeToView() void DolphinView::pasteToUrl(const KUrl& url) { - markPastedUrlsAsSelected(QApplication::clipboard()->mimeData()); - KonqOperations::doPaste(this, url); + KonqOperations* op = KonqOperations::doPasteV2(this, url); + if (op) { + m_clearSelectionBeforeSelectingNewItems = true; + connect(op, SIGNAL(aboutToCreate(KUrl::List)), this, SLOT(slotAboutToCreate(KUrl::List))); + } } KUrl::List DolphinView::simplifiedSelectedUrls() const @@ -1552,18 +1562,6 @@ QMimeData* DolphinView::selectionMimeData() const return m_model->createMimeData(selectedIndexes); } -void DolphinView::markPastedUrlsAsSelected(const QMimeData* mimeData) -{ - const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData); - KUrl::List destUrls; - foreach (const KUrl& source, sourceUrls) { - KUrl destination(url().url() + '/' + source.fileName()); - destUrls << destination; - } - markUrlsAsSelected(destUrls); - m_clearSelectionBeforeSelectingNewItems = true; -} - void DolphinView::updateWritableState() { const bool wasFolderWritable = m_isFolderWritable; diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h index a2fe9f62a..13cc66545 100644 --- a/src/views/dolphinview.h +++ b/src/views/dolphinview.h @@ -566,6 +566,11 @@ private slots: void slotModelChanged(KItemModelBase* current, KItemModelBase* previous); void slotMouseButtonPressed(int itemIndex, Qt::MouseButtons buttons); + /* + * Is called when new items get pasted or dropped. + */ + void slotAboutToCreate(const KUrl::List& urls); + /** * Emits the signal \a selectionChanged() with a small delay. This is * because getting all file items for the selection can be an expensive @@ -722,14 +727,6 @@ private: QMimeData* selectionMimeData() const; /** - * Is invoked after a paste operation or a drag & drop - * operation and URLs from \a mimeData as selected. - * This allows to select all newly pasted - * items in restoreViewState(). - */ - void markPastedUrlsAsSelected(const QMimeData* mimeData); - - /** * Updates m_isFolderWritable dependent on whether the folder represented by * the current URL is writable. If the state has changed, the signal * writeableStateChanged() will be emitted. diff --git a/src/views/draganddrophelper.cpp b/src/views/draganddrophelper.cpp index f81d4d0bf..f8ae0ad03 100644 --- a/src/views/draganddrophelper.cpp +++ b/src/views/draganddrophelper.cpp @@ -28,10 +28,13 @@ #include <QtDBus> #include <QDropEvent> -QString DragAndDropHelper::dropUrls(const KFileItem& destItem, const KUrl& destUrl, QDropEvent* event) +KonqOperations* DragAndDropHelper::dropUrls(const KFileItem& destItem, const KUrl& destUrl, QDropEvent* event, QString& error) { + error.clear(); + if (!destItem.isNull() && !destItem.isWritable()) { - return i18nc("@info:status", "Access denied. Could not write to <filename>%1</filename>", destUrl.pathOrUrl()); + error = i18nc("@info:status", "Access denied. Could not write to <filename>%1</filename>", destUrl.pathOrUrl()); + return 0; } const QMimeData* mimeData = event->mimeData(); @@ -49,15 +52,16 @@ QString DragAndDropHelper::dropUrls(const KFileItem& destItem, const KUrl& destU const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData()); foreach (const KUrl& url, urls) { if (url == destUrl) { - return i18nc("@info:status", "A folder cannot be dropped into itself"); + error = i18nc("@info:status", "A folder cannot be dropped into itself"); + return 0; } } - KonqOperations::doDrop(destItem, destUrl, event, QApplication::activeWindow()); + return KonqOperations::doDrop(destItem, destUrl, event, QApplication::activeWindow(), QList<QAction*>()); } else { - KonqOperations::doDrop(KFileItem(), destUrl, event, QApplication::activeWindow()); + return KonqOperations::doDrop(KFileItem(), destUrl, event, QApplication::activeWindow(), QList<QAction*>()); } - return QString(); + return 0; } diff --git a/src/views/draganddrophelper.h b/src/views/draganddrophelper.h index ac16f7cf2..eda5fc5c2 100644 --- a/src/views/draganddrophelper.h +++ b/src/views/draganddrophelper.h @@ -29,6 +29,7 @@ class KFileItem; class KUrl; class QDropEvent; class QWidget; +class KonqOperations; class LIBDOLPHINPRIVATE_EXPORT DragAndDropHelper { @@ -46,13 +47,15 @@ public: * @param destUrl URL of the item destination. Is used only if destItem::isNull() * is true. * @param event Drop event. - * @return Error message intended to be shown for users if dropping is not + * @param error Error message intended to be shown for users if dropping is not * possible. If an empty string is returned, the dropping has been * successful. + * @return KonqOperations pointer */ - static QString dropUrls(const KFileItem& destItem, - const KUrl& destUrl, - QDropEvent* event); + static KonqOperations* dropUrls(const KFileItem& destItem, + const KUrl& destUrl, + QDropEvent* event, + QString& error); }; #endif diff --git a/src/views/versioncontrol/updateitemstatesthread.cpp b/src/views/versioncontrol/updateitemstatesthread.cpp index e07d72c76..fa005f8f1 100644 --- a/src/views/versioncontrol/updateitemstatesthread.cpp +++ b/src/views/versioncontrol/updateitemstatesthread.cpp @@ -23,13 +23,13 @@ #include <QMutexLocker> -UpdateItemStatesThread::UpdateItemStatesThread() : +UpdateItemStatesThread::UpdateItemStatesThread(KVersionControlPlugin* plugin, + const QList<VersionControlObserver::ItemState>& itemStates) : QThread(), m_globalPluginMutex(0), - m_plugin(0), - m_itemMutex(), + m_plugin(plugin), m_retrievedItems(false), - m_itemStates() + m_itemStates(itemStates) { // Several threads may share one instance of a plugin. A global // mutex is required to serialize the retrieval of version control @@ -42,32 +42,16 @@ UpdateItemStatesThread::~UpdateItemStatesThread() { } -void UpdateItemStatesThread::setData(KVersionControlPlugin* plugin, - const QList<VersionControlObserver::ItemState>& itemStates) -{ - // The locks are taken in the same order as in run() - // to avoid potential deadlock. - QMutexLocker pluginLocker(m_globalPluginMutex); - QMutexLocker itemLocker(&m_itemMutex); - - m_itemStates = itemStates; - m_plugin = plugin; -} - void UpdateItemStatesThread::run() { Q_ASSERT(!m_itemStates.isEmpty()); Q_ASSERT(m_plugin); - QMutexLocker itemLocker(&m_itemMutex); - const QString directory = m_itemStates.first().item.url().directory(KUrl::AppendTrailingSlash); m_retrievedItems = false; - itemLocker.unlock(); QMutexLocker pluginLocker(m_globalPluginMutex); if (m_plugin->beginRetrieval(directory)) { - itemLocker.relock(); const int count = m_itemStates.count(); KVersionControlPlugin2* pluginV2 = qobject_cast<KVersionControlPlugin2*>(m_plugin); @@ -99,13 +83,11 @@ void UpdateItemStatesThread::unlockPlugin() QList<VersionControlObserver::ItemState> UpdateItemStatesThread::itemStates() const { - QMutexLocker locker(&m_itemMutex); return m_itemStates; } bool UpdateItemStatesThread::retrievedItems() const { - QMutexLocker locker(&m_itemMutex); return m_retrievedItems; } diff --git a/src/views/versioncontrol/updateitemstatesthread.h b/src/views/versioncontrol/updateitemstatesthread.h index f0f91d7d2..a28169755 100644 --- a/src/views/versioncontrol/updateitemstatesthread.h +++ b/src/views/versioncontrol/updateitemstatesthread.h @@ -38,9 +38,6 @@ class LIBDOLPHINPRIVATE_EXPORT UpdateItemStatesThread : public QThread Q_OBJECT public: - UpdateItemStatesThread(); - virtual ~UpdateItemStatesThread(); - /** * @param plugin Version control plugin that is used to update the * state of the items. Whenever the plugin is accessed @@ -49,8 +46,9 @@ public: * UpdateItemStatesThread::unlockPlugin() must be used. * @param itemStates List of items, where the states get updated. */ - void setData(KVersionControlPlugin* plugin, - const QList<VersionControlObserver::ItemState>& itemStates); + UpdateItemStatesThread(KVersionControlPlugin* plugin, + const QList<VersionControlObserver::ItemState>& itemStates); + virtual ~UpdateItemStatesThread(); /** * Whenever the plugin is accessed by the thread creator, lockPlugin() must @@ -76,7 +74,6 @@ private: QMutex* m_globalPluginMutex; // Protects the m_plugin globally KVersionControlPlugin* m_plugin; - mutable QMutex m_itemMutex; // Protects m_retrievedItems and m_itemStates bool m_retrievedItems; QList<VersionControlObserver::ItemState> m_itemStates; }; diff --git a/src/views/versioncontrol/versioncontrolobserver.cpp b/src/views/versioncontrol/versioncontrolobserver.cpp index 64bc26867..402a2de54 100644 --- a/src/views/versioncontrol/versioncontrolobserver.cpp +++ b/src/views/versioncontrol/versioncontrolobserver.cpp @@ -108,12 +108,7 @@ QList<QAction*> VersionControlObserver::actions(const KFileItemList& items) cons if (pluginV2) { // Use version 2 of the KVersionControlPlugin which allows providing actions // also for non-versioned directories. - if (m_updateItemStatesThread && m_updateItemStatesThread->lockPlugin()) { - actions = pluginV2->actions(items); - m_updateItemStatesThread->unlockPlugin(); - } else { - actions = pluginV2->actions(items); - } + actions = pluginV2->actions(items); } else if (isVersioned()) { // Support deprecated interfaces from KVersionControlPlugin version 1. // Context menu actions where only available for versioned directories. @@ -125,14 +120,8 @@ QList<QAction*> VersionControlObserver::actions(const KFileItemList& items) cons } } - if (m_updateItemStatesThread && m_updateItemStatesThread->lockPlugin()) { - actions = directory.isEmpty() ? m_plugin->contextMenuActions(items) - : m_plugin->contextMenuActions(directory); - m_updateItemStatesThread->unlockPlugin(); - } else { - actions = directory.isEmpty() ? m_plugin->contextMenuActions(items) - : m_plugin->contextMenuActions(directory); - } + actions = directory.isEmpty() ? m_plugin->contextMenuActions(items) + : m_plugin->contextMenuActions(directory); } return actions; @@ -238,20 +227,12 @@ void VersionControlObserver::slotThreadFinished() void VersionControlObserver::updateItemStates() { Q_ASSERT(m_plugin); - if (!m_updateItemStatesThread) { - m_updateItemStatesThread = new UpdateItemStatesThread(); - connect(m_updateItemStatesThread, SIGNAL(finished()), - this, SLOT(slotThreadFinished())); - connect(m_updateItemStatesThread, SIGNAL(finished()), - m_updateItemStatesThread, SLOT(deleteLater())); - } - else { + if (m_updateItemStatesThread) { // An update is currently ongoing. Wait until the thread has finished // the update (see slotThreadFinished()). m_pendingItemStatesUpdate = true; return; } - QList<ItemState> itemStates; const int itemCount = m_model->count(); itemStates.reserve(itemCount); @@ -269,7 +250,12 @@ void VersionControlObserver::updateItemStates() if (!m_silentUpdate) { emit infoMessage(i18nc("@info:status", "Updating version information...")); } - m_updateItemStatesThread->setData(m_plugin, itemStates); + m_updateItemStatesThread = new UpdateItemStatesThread(m_plugin, itemStates); + connect(m_updateItemStatesThread, SIGNAL(finished()), + this, SLOT(slotThreadFinished())); + connect(m_updateItemStatesThread, SIGNAL(finished()), + m_updateItemStatesThread, SLOT(deleteLater())); + m_updateItemStatesThread->start(); // slotThreadFinished() is called when finished } } |
