]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinview.cpp
Update the FSF address to 51 Franklin Street (hopefully it is the right one)
[dolphin.git] / src / dolphinview.cpp
index abc27167d9a8c2ed01f42398ed62739162581190..3aa4e54626f1cd0b0975282a8f4513e5875a3891 100644 (file)
  *   You should have received a copy of the GNU General Public License     *
  *   along with this program; if not, write to the                         *
  *   Free Software Foundation, Inc.,                                       *
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
  ***************************************************************************/
 
 #include "dolphinview.h"
 
-#include <kdirmodel.h>
+#include <QItemSelectionModel>
 
+#include <kdirmodel.h>
 
 #include <qlayout.h>
 //Added by qt3to4:
 #include <Q3ValueList>
 #include <QDropEvent>
 #include <QMouseEvent>
-#include <Q3VBoxLayout>
+#include <QVBoxLayout>
 #include <kurl.h>
 #include <klocale.h>
 #include <kio/netaccess.h>
@@ -38,7 +39,7 @@
 
 #include "urlnavigator.h"
 #include "dolphinstatusbar.h"
-#include "dolphin.h"
+#include "dolphinmainwindow.h"
 #include "dolphindirlister.h"
 #include "viewproperties.h"
 #include "dolphindetailsview.h"
 
 #include "filterbar.h"
 
-DolphinView::DolphinView(QWidget *parent,
+DolphinView::DolphinView(DolphinMainWindow *mainWindow,
+                         QWidget *parent,
                          const KUrl& url,
                          Mode mode,
                          bool showHiddenFiles) :
     QWidget(parent),
+    m_mainWindow(mainWindow),
     m_refreshing(false),
     m_showProgress(false),
     m_mode(mode),
@@ -64,27 +67,28 @@ DolphinView::DolphinView(QWidget *parent,
     m_fileCount(0),
     m_filterBar(0)
 {
+    hide();
     setFocusPolicy(Qt::StrongFocus);
-    m_topLayout = new Q3VBoxLayout(this);
-
-    Dolphin& dolphin = Dolphin::mainWin();
+    m_topLayout = new QVBoxLayout(this);
+    m_topLayout->setSpacing(0);
+    m_topLayout->setMargin(0);
 
     connect(this, SIGNAL(signalModeChanged()),
-            &dolphin, SLOT(slotViewModeChanged()));
+            mainWindow, SLOT(slotViewModeChanged()));
     connect(this, SIGNAL(signalShowHiddenFilesChanged()),
-            &dolphin, SLOT(slotShowHiddenFilesChanged()));
+            mainWindow, SLOT(slotShowHiddenFilesChanged()));
     connect(this, SIGNAL(signalSortingChanged(DolphinView::Sorting)),
-            &dolphin, SLOT(slotSortingChanged(DolphinView::Sorting)));
+            mainWindow, SLOT(slotSortingChanged(DolphinView::Sorting)));
     connect(this, SIGNAL(signalSortOrderChanged(Qt::SortOrder)),
-            &dolphin, SLOT(slotSortOrderChanged(Qt::SortOrder)));
+            mainWindow, SLOT(slotSortOrderChanged(Qt::SortOrder)));
 
     m_urlNavigator = new UrlNavigator(url, this);
     connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)),
             this, SLOT(slotUrlChanged(const KUrl&)));
     connect(m_urlNavigator, SIGNAL(urlChanged(const KUrl&)),
-            &dolphin, SLOT(slotUrlChanged(const KUrl&)));
+            mainWindow, SLOT(slotUrlChanged(const KUrl&)));
     connect(m_urlNavigator, SIGNAL(historyChanged()),
-            &dolphin, SLOT(slotHistoryChanged()));
+            mainWindow, SLOT(slotHistoryChanged()));
 
     m_statusBar = new DolphinStatusBar(this);
 
@@ -119,7 +123,7 @@ DolphinView::DolphinView(QWidget *parent,
 
     m_iconSize = K3Icon::SizeMedium;
 
-    m_filterBar = new FilterBar(this);
+    m_filterBar = new FilterBar(mainWindow, this);
     m_filterBar->hide();
     connect(m_filterBar, SIGNAL(signalFilterChanged(const QString&)),
            this, SLOT(slotChangeNameFilter(const QString&)));
@@ -150,12 +154,12 @@ const KUrl& DolphinView::url() const
 
 void DolphinView::requestActivation()
 {
-    Dolphin::mainWin().setActiveView(this);
+    mainWindow()->setActiveView(this);
 }
 
 bool DolphinView::isActive() const
 {
-    return (Dolphin::mainWin().activeView() == this);
+    return (mainWindow()->activeView() == this);
 }
 
 void DolphinView::setMode(Mode mode)
@@ -221,7 +225,7 @@ void DolphinView::renameSelectedItems()
             return;
         }
 
-        DolphinView* view = Dolphin::mainWin().activeView();
+        DolphinView* view = mainWindow()->activeView();
         const QString& newName = dialog.newName();
         if (newName.isEmpty()) {
             view->statusBar()->setMessage(i18n("The new item name is invalid."),
@@ -235,12 +239,13 @@ void DolphinView::renameSelectedItems()
 
             const int urlsCount = urls.count();
             ProgressIndicator* progressIndicator =
-                new  ProgressIndicator(i18n("Renaming items..."),
+                new  ProgressIndicator(mainWindow(),
+                                       i18n("Renaming items..."),
                                        i18n("Renaming finished."),
                                        urlsCount);
 
             // iterate through all selected items and rename them...
-            const int replaceIndex = newName.find('#');
+            const int replaceIndex = newName.indexOf('#');
             assert(replaceIndex >= 0);
             for (int i = 0; i < urlsCount; ++i) {
                 const KUrl& source = urls[i];
@@ -479,29 +484,42 @@ const Q3ValueList<UrlNavigator::HistoryElem> DolphinView::urlHistory(int& index)
 
 bool DolphinView::hasSelection() const
 {
-    const KFileItemList* list = selectedItems();
-    return (list != 0) && !list->isEmpty();
+    return m_iconsView->selectionModel()->hasSelection();
 }
 
-const KFileItemList* DolphinView::selectedItems() const
+KFileItemList DolphinView::selectedItems() const
 {
-    return 0; //fileView()->selectedItems();
+    QItemSelectionModel* selModel = m_iconsView->selectionModel();
+    assert(selModel != 0);
+
+    KFileItemList itemList;
+    if (selModel->hasSelection()) {
+       KDirModel* dirModel = static_cast<KDirModel*>(m_iconsView->model());
+       const QModelIndexList indexList = selModel->selectedIndexes();
+
+        QModelIndexList::const_iterator end = indexList.end();
+        for (QModelIndexList::const_iterator it = indexList.begin(); it != end; ++it) {
+           KFileItem* item = dirModel->itemForIndex(*it);
+           if (item != 0) {
+               itemList.append(item);
+           }
+        }
+    }
+    return itemList;
 }
 
 KUrl::List DolphinView::selectedUrls() const
 {
     KUrl::List urls;
 
-    /*const KFileItemList* list = fileView()->selectedItems();
-    if (list != 0) {
-        KFileItemList::const_iterator it = list->begin();
-        const KFileItemList::const_iterator end = list->end();
-        while (it != end) {
-            KFileItem* item = *it;
-            urls.append(item->url());
-            ++it;
-        }
-    }*/
+    const KFileItemList list = selectedItems();
+    KFileItemList::const_iterator it = list.begin();
+    const KFileItemList::const_iterator end = list.end();
+    while (it != end) {
+        KFileItem* item = *it;
+        urls.append(item->url());
+        ++it;
+    }
 
     return urls;
 }
@@ -530,7 +548,7 @@ void DolphinView::rename(const KUrl& source, const QString& newName)
 
     const bool destExists = KIO::NetAccess::exists(dest,
                                                    false,
-                                                   Dolphin::mainWin().activeView());
+                                                   mainWindow()->activeView());
     if (destExists) {
         // the destination already exists, hence ask the user
         // how to proceed...
@@ -601,13 +619,18 @@ void DolphinView::slotUrlListDropped(QDropEvent* /* event */,
         }
     }
 
-    Dolphin::mainWin().dropUrls(urls, destination);
+    mainWindow()->dropUrls(urls, destination);
 }
 
 void DolphinView::mouseReleaseEvent(QMouseEvent* event)
 {
     QWidget::mouseReleaseEvent(event);
-    Dolphin::mainWin().setActiveView(this);
+    mainWindow()->setActiveView(this);
+}
+
+DolphinMainWindow* DolphinView::mainWindow() const
+{
+    return m_mainWindow;
 }
 
 void DolphinView::slotUrlChanged(const KUrl& url)
@@ -628,7 +651,7 @@ void DolphinView::slotUrlChanged(const KUrl& url)
     // created. The application does not care whether a view is represented by a
     // different instance, hence inform the application that the selection might have
     // changed so that it can update it's actions.
-    Dolphin::mainWin().slotSelectionChanged();
+    mainWindow()->slotSelectionChanged();
 
     emit signalUrlChanged(url);
 }
@@ -644,7 +667,7 @@ void DolphinView::triggerIconsViewItem(Q3IconViewItem* item)
         // Updating the Url must be done outside the scope of this slot,
         // as iconview items will get deleted.
         QTimer::singleShot(0, this, SLOT(updateUrl()));
-        Dolphin::mainWin().setActiveView(this);
+        mainWindow()->setActiveView(this);
     }
 }
 
@@ -795,7 +818,7 @@ void DolphinView::slotErrorMessage(const QString& msg)
 
 void DolphinView::slotGrabActivation()
 {
-    Dolphin::mainWin().setActiveView(this);
+    mainWindow()->setActiveView(this);
 }
 
 void DolphinView::slotContentsMoving(int x, int y)
@@ -897,14 +920,18 @@ QString DolphinView::selectionStatusBarText() const
     // TODO: the following code is not suitable for languages where multiple forms
     // of plurals are given (e. g. in Poland three forms of plurals exist).
     QString text;
-    const KFileItemList* list = selectedItems();
-    assert((list != 0) && !list->isEmpty());
+    const KFileItemList list = selectedItems();
+    if (list.isEmpty()) {
+        // TODO: assert(!list.isEmpty()) should be used, as this method is only invoked if
+        // DolphinView::hasSelection() is true. Inconsistent behavior?
+        return QString();
+    }
 
     int fileCount = 0;
     int folderCount = 0;
     KIO::filesize_t byteSize = 0;
-    KFileItemList::const_iterator it = list->begin();
-    const KFileItemList::const_iterator end = list->end();
+    KFileItemList::const_iterator it = list.begin();
+    const KFileItemList::const_iterator end = list.end();
     while (it != end){
         KFileItem* item = *it;
         if (item->isDir()) {
@@ -969,6 +996,11 @@ void DolphinView::slotShowFilterBar(bool show)
     }
 }
 
+void DolphinView::declareViewActive()
+{
+    mainWindow()->setActiveView( this );
+}
+
 void DolphinView::slotChangeNameFilter(const QString& nameFilter)
 {
     // The name filter of KDirLister does a 'hard' filtering, which