* 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>
#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),
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);
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&)));
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)
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."),
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];
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;
}
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...
}
}
- 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)
// 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);
}
// 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);
}
}
void DolphinView::slotGrabActivation()
{
- Dolphin::mainWin().setActiveView(this);
+ mainWindow()->setActiveView(this);
}
void DolphinView::slotContentsMoving(int x, int y)
// 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()) {
}
}
+void DolphinView::declareViewActive()
+{
+ mainWindow()->setActiveView( this );
+}
+
void DolphinView::slotChangeNameFilter(const QString& nameFilter)
{
// The name filter of KDirLister does a 'hard' filtering, which