]> 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 e60f6f655a7b52321b8c899dfd60691132d52df3..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>
@@ -66,8 +67,11 @@ DolphinView::DolphinView(DolphinMainWindow *mainWindow,
     m_fileCount(0),
     m_filterBar(0)
 {
+    hide();
     setFocusPolicy(Qt::StrongFocus);
-    m_topLayout = new Q3VBoxLayout(this);
+    m_topLayout = new QVBoxLayout(this);
+    m_topLayout->setSpacing(0);
+    m_topLayout->setMargin(0);
 
     connect(this, SIGNAL(signalModeChanged()),
             mainWindow, SLOT(slotViewModeChanged()));
@@ -241,7 +245,7 @@ void DolphinView::renameSelectedItems()
                                        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];
@@ -480,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;
 }
@@ -903,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()) {