]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Merge remote-tracking branch 'origin/KDE/4.10'
authorFrank Reininghaus <frank78ac@googlemail.com>
Mon, 10 Jun 2013 19:40:41 +0000 (21:40 +0200)
committerFrank Reininghaus <frank78ac@googlemail.com>
Mon, 10 Jun 2013 19:40:41 +0000 (21:40 +0200)
1  2 
src/views/dolphinview.cpp
src/views/dolphinview.h

index 53d3277085c46c1e1063e6c230eac8b19d24dbe9,d69d664afaa5bc776d92db11235e9341800cfaa2..16b92801be73f6a299dff96c0a6c7506f03f6b42
@@@ -33,8 -33,6 +33,8 @@@
  #include <QTimer>
  #include <QScrollBar>
  
 +#include <KDesktopFile>
 +#include <KProtocolManager>
  #include <KActionCollection>
  #include <KColorScheme>
  #include <KDirModel>
@@@ -104,7 -102,6 +104,7 @@@ DolphinView::DolphinView(const KUrl& ur
      m_restoredContentsPosition(),
      m_selectedUrls(),
      m_clearSelectionBeforeSelectingNewItems(false),
 +    m_markFirstNewlySelectedItemAsCurrent(false),
      m_versionControlObserver(0)
  {
      m_topLayout = new QVBoxLayout(this);
              this, SLOT(slotSortRoleChangedByHeader(QByteArray,QByteArray)));
      connect(m_view, SIGNAL(visibleRolesChanged(QList<QByteArray>,QList<QByteArray>)),
              this, SLOT(slotVisibleRolesChangedByHeader(QList<QByteArray>,QList<QByteArray>)));
-     connect(m_view, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
-             this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
+     connect(m_view, SIGNAL(roleEditingCanceled(int,QByteArray,QVariant)),
+             this, SLOT(slotRoleEditingCanceled(int,QByteArray,QVariant)));
      connect(m_view->header(), SIGNAL(columnWidthChanged(QByteArray,qreal,qreal)),
              this, SLOT(slotHeaderColumnWidthChanged(QByteArray,qreal,qreal)));
  
@@@ -612,6 -609,9 +612,9 @@@ void DolphinView::setUrl(const KUrl& ur
  
      hideToolTip();
  
+     disconnect(m_view, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
+                this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
      // It is important to clear the items from the model before
      // applying the view properties, otherwise expensive operations
      // might be done on the existing items although they get cleared
@@@ -651,6 -651,9 +654,9 @@@ void DolphinView::renameSelectedItems(
      if (items.count() == 1 && GeneralSettings::renameInline()) {
          const int index = m_model->index(items.first());
          m_view->editRole(index, "text");
+         connect(m_view, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
+                 this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
      } else {
          RenameDialog* dialog = new RenameDialog(this, items);
          dialog->setAttribute(Qt::WA_DeleteOnClose);
@@@ -812,10 -815,9 +818,10 @@@ void DolphinView::slotItemsActivated(co
      while (it.hasNext()) {
          const int index = it.next();
          KFileItem item = m_model->fileItem(index);
 +        const KUrl& url = openItemAsFolderUrl(item);
  
 -        if (item.isDir()) { // Open folders in new tabs
 -            emit tabRequested(item.url());
 +        if (!url.isEmpty()) { // Open folders in new tabs
 +            emit tabRequested(url);
          } else {
              items.append(item);
          }
  
  void DolphinView::slotItemMiddleClicked(int index)
  {
 -    const KFileItem item = m_model->fileItem(index);
 -    if (item.isDir() || isTabsForFilesEnabled()) {
 +    const KFileItem& item = m_model->fileItem(index);
 +    const KUrl& url = openItemAsFolderUrl(item);
 +    if (!url.isEmpty()) {
 +        emit tabRequested(url);
 +    } else if (isTabsForFilesEnabled()) {
          emit tabRequested(item.url());
      }
  }
@@@ -1030,19 -1029,15 +1036,19 @@@ void DolphinView::slotItemDropEvent(in
                           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)));
      }
 +
 +    setActive(true);
  }
  
  void DolphinView::slotModelChanged(KItemModelBase* current, KItemModelBase* previous)
@@@ -1077,17 -1072,6 +1083,17 @@@ void DolphinView::slotMouseButtonPresse
      }
  }
  
 +void DolphinView::slotAboutToCreate(const KUrl::List& urls)
 +{
 +    if (!urls.isEmpty()) {
 +        if (m_markFirstNewlySelectedItemAsCurrent) {
 +            markUrlAsCurrent(urls.first());
 +            m_markFirstNewlySelectedItemAsCurrent = false;
 +        }
 +        m_selectedUrls << urls;
 +    }
 +}
 +
  void DolphinView::slotSelectionChanged(const QSet<int>& current, const QSet<int>& previous)
  {
      const int currentCount = current.count();
@@@ -1210,46 -1194,6 +1216,46 @@@ QString DolphinView::viewPropertiesCont
      return m_viewPropertiesContext;
  }
  
 +KUrl DolphinView::openItemAsFolderUrl(const KFileItem& item, const bool browseThroughArchives)
 +{
 +    if (item.isNull()) {
 +        return KUrl();
 +    }
 +
 +    KUrl url = item.targetUrl();
 +
 +    if (item.isDir()) {
 +        return url;
 +    }
 +
 +    if (item.isMimeTypeKnown()) {
 +        const QString& mimetype = item.mimetype();
 +
 +        if (browseThroughArchives && item.isFile() && url.isLocalFile()) {
 +            // Generic mechanism for redirecting to tar:/<path>/ when clicking on a tar file,
 +            // zip:/<path>/ when clicking on a zip file, etc.
 +            // The .protocol file specifies the mimetype that the kioslave handles.
 +            // Note that we don't use mimetype inheritance since we don't want to
 +            // open OpenDocument files as zip folders...
 +            const QString& protocol = KProtocolManager::protocolForArchiveMimetype(mimetype);
 +            if (!protocol.isEmpty()) {
 +                url.setProtocol(protocol);
 +                return url;
 +            }
 +        }
 +
 +        if (mimetype == QLatin1String("application/x-desktop")) {
 +            // Redirect to the URL in Type=Link desktop files
 +            KDesktopFile desktopFile(url.toLocalFile());
 +            if (desktopFile.hasLinkType()) {
 +                return desktopFile.readUrl();
 +            }
 +        }
 +    }
 +
 +    return KUrl();
 +}
 +
  void DolphinView::observeCreatedItem(const KUrl& url)
  {
      if (m_active) {
@@@ -1280,11 -1224,10 +1286,11 @@@ void DolphinView::updateViewState(
                  m_view->scrollToItem(currentIndex);
                  m_scrollToCurrentItem = false;
              }
 +
 +            m_currentItemUrl = KUrl();
          } else {
              selectionManager->setCurrentItem(0);
          }
 -        m_currentItemUrl = KUrl();
      }
  
      if (!m_restoredContentsPosition.isNull()) {
@@@ -1363,16 -1306,6 +1369,16 @@@ void DolphinView::slotDeleteFileFinishe
      }
  }
  
 +void DolphinView::slotRenamingFailed(const KUrl& oldUrl, const KUrl& newUrl)
 +{
 +    const int index = m_model->index(newUrl);
 +    if (index >= 0) {
 +        QHash<QByteArray, QVariant> data;
 +        data.insert("text", oldUrl.fileName());
 +        m_model->setData(index, data);
 +    }
 +}
 +
  void DolphinView::slotDirectoryLoadingStarted()
  {
      // Disable the writestate temporary until it can be determined in a fast way
@@@ -1439,8 -1372,17 +1445,17 @@@ void DolphinView::slotVisibleRolesChang
      emit visibleRolesChanged(m_visibleRoles, previousVisibleRoles);
  }
  
+ void DolphinView::slotRoleEditingCanceled(int index, const QByteArray& role, const QVariant& value)
+ {
+     disconnect(m_view, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
+                this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
+ }
  void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value)
  {
+     disconnect(m_view, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
+                this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
      if (index < 0 || index >= m_model->count()) {
          return;
      }
                  m_model->setData(index, data);
              }
  
 -            KonqOperations::rename(this, oldUrl, newName);
 +            KonqOperations* op = KonqOperations::renameV2(this, oldUrl, newName);
 +            if (op) {
 +                connect(op, SIGNAL(renamingFailed(KUrl,KUrl)), SLOT(slotRenamingFailed(KUrl,KUrl)));
 +            }
          }
      }
  }
@@@ -1599,12 -1538,8 +1614,12 @@@ 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;
 +        m_markFirstNewlySelectedItemAsCurrent = true;
 +        connect(op, SIGNAL(aboutToCreate(KUrl::List)), this, SLOT(slotAboutToCreate(KUrl::List)));
 +    }
  }
  
  KUrl::List DolphinView::simplifiedSelectedUrls() const
@@@ -1632,6 -1567,18 +1647,6 @@@ QMimeData* DolphinView::selectionMimeDa
      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 --combined src/views/dolphinview.h
index 0cd6ff2f476f09854b934f2be959402af23f8bbf,62b5df7c77997444210c5c46aff0da6af58a62c8..d77a3a19806cbe8b1ecc1349b82009ef4c3db826
@@@ -304,14 -304,6 +304,14 @@@ public
      void setViewPropertiesContext(const QString& context);
      QString viewPropertiesContext() const;
  
 +    /**
 +     * Checks if the given \a item can be opened as folder (e.g. archives).
 +     * This function will also adjust the \a url (e.g. change the protocol).
 +     * @return a valid and adjusted url if the item can be opened as folder,
 +     * otherwise return an empty url.
 +     */
 +    static KUrl openItemAsFolderUrl(const KFileItem& item, const bool browseThroughArchives = true);
 +
  public slots:
      /**
       * Changes the directory to \a url. If the current directory is equal to
@@@ -574,11 -566,6 +574,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
       */
      void slotDeleteFileFinished(KJob* job);
  
 +    void slotRenamingFailed(const KUrl& oldUrl, const KUrl& newUrl);
 +
      /**
       * Invoked when the file item model has started the loading
       * of the directory specified by DolphinView::url().
      void slotVisibleRolesChangedByHeader(const QList<QByteArray>& current,
                                           const QList<QByteArray>& previous);
  
+     void slotRoleEditingCanceled(int index, const QByteArray& role, const QVariant& value);
      void slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value);
  
      /**
@@@ -736,6 -722,14 +737,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
@@@ -779,7 -773,6 +780,7 @@@ private
  
      QList<KUrl> m_selectedUrls; // Used for making the view to remember selections after F5
      bool m_clearSelectionBeforeSelectingNewItems;
 +    bool m_markFirstNewlySelectedItemAsCurrent;
  
      VersionControlObserver* m_versionControlObserver;