* 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 <qlayout.h>
-//Added by qt3to4:
+#include <QItemSelectionModel>
#include <Q3ValueList>
#include <QDropEvent>
#include <QMouseEvent>
-#include <Q3VBoxLayout>
+#include <QVBoxLayout>
+
+#include <kdirmodel.h>
+#include <kfileitemdelegate.h>
#include <kurl.h>
#include <klocale.h>
#include <kio/netaccess.h>
#include <kio/renamedlg.h>
+#include <kmimetyperesolver.h>
#include <assert.h>
#include "urlnavigator.h"
#include "dolphinstatusbar.h"
-#include "dolphin.h"
+#include "dolphinmainwindow.h"
#include "dolphindirlister.h"
+#include "dolphinsortfilterproxymodel.h"
#include "viewproperties.h"
#include "dolphindetailsview.h"
#include "dolphiniconsview.h"
#include "undomanager.h"
#include "renamedialog.h"
#include "progressindicator.h"
-
#include "filterbar.h"
-DolphinView::DolphinView(QWidget *parent,
+DolphinView::DolphinView(DolphinMainWindow *mainWindow,
+ QWidget *parent,
const KUrl& url,
Mode mode,
bool showHiddenFiles) :
m_refreshing(false),
m_showProgress(false),
m_mode(mode),
- m_iconsView(0),
- m_detailsView(0),
- m_statusBar(0),
m_iconSize(0),
m_folderCount(0),
m_fileCount(0),
- m_filterBar(0)
+ m_mainWindow(mainWindow),
+ m_topLayout(0),
+ m_urlNavigator(0),
+ m_iconsView(0),
+ m_filterBar(0),
+ m_statusBar(0),
+ m_dirModel(0),
+ m_dirLister(0),
+ m_proxyModel(0)
{
+ hide();
setFocusPolicy(Qt::StrongFocus);
- m_topLayout = new Q3VBoxLayout(this);
-
- Dolphin& dolphin = Dolphin::mainWin();
-
- connect(this, SIGNAL(signalModeChanged()),
- &dolphin, SLOT(slotViewModeChanged()));
- connect(this, SIGNAL(signalShowHiddenFilesChanged()),
- &dolphin, SLOT(slotShowHiddenFilesChanged()));
- connect(this, SIGNAL(signalSortingChanged(DolphinView::Sorting)),
- &dolphin, SLOT(slotSortingChanged(DolphinView::Sorting)));
- connect(this, SIGNAL(signalSortOrderChanged(Qt::SortOrder)),
- &dolphin, SLOT(slotSortOrderChanged(Qt::SortOrder)));
+ m_topLayout = new QVBoxLayout(this);
+ m_topLayout->setSpacing(0);
+ m_topLayout->setMargin(0);
- m_urlNavigator = new URLNavigator(url, this);
+ 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&)));
- connect(m_urlNavigator, SIGNAL(historyChanged()),
- &dolphin, SLOT(slotHistoryChanged()));
+ this, SLOT(loadDirectory(const KUrl&)));
m_statusBar = new DolphinStatusBar(this);
this, SLOT(slotInfoMessage(const QString&)));
connect(m_dirLister, SIGNAL(errorMessage(const QString&)),
this, SLOT(slotErrorMessage(const QString&)));
- connect(m_dirLister, SIGNAL(refreshItems(const KFileItemList&)),
- this, SLOT(slotRefreshItems(const KFileItemList&)));
- connect(m_dirLister, SIGNAL(redirection(const KUrl&, const KUrl&)),
- this, SIGNAL(redirection(const KUrl&, const KUrl&)));
- connect(m_dirLister, SIGNAL(newItems(const KFileItemList&)),
- this, SLOT(slotAddItems(const KFileItemList&)));
- m_iconSize = K3Icon::SizeMedium;
+ m_iconsView = new DolphinIconsView(this);
+ applyModeToView();
- m_topLayout->addWidget(m_urlNavigator);
- createView();
+ m_dirModel = new KDirModel();
+ m_dirModel->setDirLister(m_dirLister);
+
+ m_proxyModel = new DolphinSortFilterProxyModel(this);
+ m_proxyModel->setSourceModel(m_dirModel);
+
+ m_iconsView->setModel(m_dirModel); // TODO: using m_proxyModel crashes when clicking on an item
+
+ KFileItemDelegate* delegate = new KFileItemDelegate(this);
+ delegate->setAdditionalInformation(KFileItemDelegate::FriendlyMimeType);
+ m_iconsView->setItemDelegate(delegate);
+
+ m_dirLister->setDelayedMimeTypes(true);
+ new KMimeTypeResolver(m_iconsView, m_dirModel);
+
+ m_iconSize = K3Icon::SizeMedium;
m_filterBar = new FilterBar(this);
m_filterBar->hide();
- m_topLayout->addWidget(m_filterBar);
- connect(m_filterBar, SIGNAL(signalFilterChanged(const QString&)),
+ connect(m_filterBar, SIGNAL(filterChanged(const QString&)),
this, SLOT(slotChangeNameFilter(const QString&)));
+ connect(m_filterBar, SIGNAL(closed()),
+ this, SLOT(closeFilterBar()));
+ m_topLayout->addWidget(m_urlNavigator);
+ m_topLayout->addWidget(m_iconsView);
+ m_topLayout->addWidget(m_filterBar);
m_topLayout->addWidget(m_statusBar);
+
+ connect(m_iconsView, SIGNAL(clicked(const QModelIndex&)),
+ this, SLOT(triggerItem(const QModelIndex&)));
+ connect(m_iconsView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
+ this, SLOT(emitSelectionChangedSignal()));
+
+ startDirLister(m_urlNavigator->url());
}
DolphinView::~DolphinView()
m_dirLister = 0;
}
-void DolphinView::setURL(const KUrl& url)
+void DolphinView::setUrl(const KUrl& url)
{
- m_urlNavigator->setURL(url);
+ m_urlNavigator->setUrl(url);
}
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)
return; // the wished mode is already set
}
- QWidget* view = (m_iconsView != 0) ? static_cast<QWidget*>(m_iconsView) :
- static_cast<QWidget*>(m_detailsView);
- if (view != 0) {
- m_topLayout->remove(view);
- view->close();
- view->deleteLater();
- m_iconsView = 0;
- m_detailsView = 0;
- }
-
m_mode = mode;
- createView();
-
ViewProperties props(m_urlNavigator->url());
props.setViewMode(m_mode);
- emit signalModeChanged();
+ applyModeToView();
+ startDirLister(m_urlNavigator->url());
+
+ emit modeChanged();
}
DolphinView::Mode DolphinView::mode() const
return m_mode;
}
-void DolphinView::setShowHiddenFilesEnabled(bool show)
+void DolphinView::setShowHiddenFiles(bool show)
{
if (m_dirLister->showingDotFiles() == show) {
return;
}
ViewProperties props(m_urlNavigator->url());
- props.setShowHiddenFilesEnabled(show);
+ props.setShowHiddenFiles(show);
props.save();
m_dirLister->setShowingDotFiles(show);
- emit signalShowHiddenFilesChanged();
+ emit showHiddenFilesChanged();
reload();
}
-bool DolphinView::isShowHiddenFilesEnabled() const
+bool DolphinView::showHiddenFiles() const
{
return m_dirLister->showingDotFiles();
}
setMode(props.viewMode());
setSorting(props.sorting());
setSortOrder(props.sortOrder());
- setShowHiddenFilesEnabled(props.isShowHiddenFilesEnabled());
+ setShowHiddenFiles(props.showHiddenFiles());
}
void DolphinView::renameSelectedItems()
{
- const KUrl::List urls = selectedURLs();
+ const KUrl::List urls = selectedUrls();
if (urls.count() > 1) {
// More than one item has been selected for renaming. Open
// a rename dialog and rename all items afterwards.
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];
if (destExists) {
delete progressIndicator;
progressIndicator = 0;
- view->statusBar()->setMessage(i18n("Renaming failed (item '%1' already exists).").arg(name),
+ view->statusBar()->setMessage(i18n("Renaming failed (item '%1' already exists).",name),
DolphinStatusBar::Error);
break;
}
// Only one item has been selected for renaming. Use the custom
// renaming mechanism from the views.
assert(urls.count() == 1);
- if (m_mode == DetailsView) {
- Q3ListViewItem* item = m_detailsView->firstChild();
+ // TODO:
+ /*if (m_mode == DetailsView) {
+ Q3ListViewItem* item = m_iconsView->firstChild();
while (item != 0) {
if (item->isSelected()) {
- m_detailsView->rename(item, DolphinDetailsView::NameColumn);
+ m_iconsView->rename(item, DolphinDetailsView::NameColumn);
break;
}
item = item->nextSibling();
}
item = static_cast<KFileIconViewItem*>(item->nextItem());
}
- }
+ }*/
}
}
void DolphinView::selectAll()
{
- fileView()->selectAll();
+ selectAll(QItemSelectionModel::Select);
}
void DolphinView::invertSelection()
{
- fileView()->invertSelection();
+ selectAll(QItemSelectionModel::Toggle);
}
DolphinStatusBar* DolphinView::statusBar() const
int DolphinView::contentsX() const
{
- return scrollView()->contentsX();
+
+ return 0; //scrollView()->contentsX();
}
int DolphinView::contentsY() const
{
- return scrollView()->contentsY();
+ return 0; //scrollView()->contentsY();
}
void DolphinView::refreshSettings()
{
- if (m_iconsView != 0) {
- m_iconsView->refreshSettings();
- }
-
- if (m_detailsView != 0) {
- // TODO: There is no usable interface in QListView/KFileDetailView
- // to hide/show columns. The easiest approach is to delete
- // the current instance and recreate a new one, which automatically
- // refreshs the settings. If a proper interface is available in Qt4
- // m_detailsView->refreshSettings() would be enough.
- m_topLayout->remove(m_detailsView);
- m_detailsView->close();
- m_detailsView->deleteLater();
- m_detailsView = 0;
-
- createView();
- }
+ startDirLister(m_urlNavigator->url());
}
void DolphinView::updateStatusBar()
}
}
-void DolphinView::requestItemInfo(const KUrl& url)
+void DolphinView::emitRequestItemInfo(const KUrl& url)
+{
+ emit requestItemInfo(url);
+}
+
+bool DolphinView::isFilterBarVisible() const
{
- emit signalRequestItemInfo(url);
+ return m_filterBar->isVisible();
}
-bool DolphinView::isURLEditable() const
+bool DolphinView::isUrlEditable() const
{
- return m_urlNavigator->isURLEditable();
+ return m_urlNavigator->isUrlEditable();
}
void DolphinView::zoomIn()
{
- itemEffectsManager()->zoomIn();
+ //itemEffectsManager()->zoomIn();
}
void DolphinView::zoomOut()
{
- itemEffectsManager()->zoomOut();
+ //itemEffectsManager()->zoomOut();
}
bool DolphinView::isZoomInPossible() const
{
- return itemEffectsManager()->isZoomInPossible();
+ return false; //itemEffectsManager()->isZoomInPossible();
}
bool DolphinView::isZoomOutPossible() const
{
- return itemEffectsManager()->isZoomOutPossible();
+ return false; //itemEffectsManager()->isZoomOutPossible();
}
void DolphinView::setSorting(Sorting sorting)
{
if (sorting != this->sorting()) {
- KFileView* view = fileView();
- int spec = view->sorting() & ~QDir::Name & ~QDir::Size & ~QDir::Time & ~QDir::Unsorted;
-
- switch (sorting) {
- case SortByName: spec = spec | QDir::Name; break;
- case SortBySize: spec = spec | QDir::Size; break;
- case SortByDate: spec = spec | QDir::Time; break;
- default: break;
- }
-
ViewProperties props(url());
props.setSorting(sorting);
- view->setSorting(static_cast<QDir::SortSpec>(spec));
+ m_proxyModel->setSorting(sorting);
- emit signalSortingChanged(sorting);
+ emit sortingChanged(sorting);
}
}
DolphinView::Sorting DolphinView::sorting() const
{
- const QDir::SortSpec spec = fileView()->sorting();
-
- if (spec & QDir::Time) {
- return SortByDate;
- }
-
- if (spec & QDir::Size) {
- return SortBySize;
- }
-
- return SortByName;
+ return m_proxyModel->sorting();
}
void DolphinView::setSortOrder(Qt::SortOrder order)
{
if (sortOrder() != order) {
- KFileView* view = fileView();
- int sorting = view->sorting();
- sorting = (order == Qt::Ascending) ? (sorting & ~QDir::Reversed) :
- (sorting | QDir::Reversed);
-
ViewProperties props(url());
props.setSortOrder(order);
- view->setSorting(static_cast<QDir::SortSpec>(sorting));
+ m_proxyModel->setSortOrder(order);
- emit signalSortOrderChanged(order);
+ emit sortOrderChanged(order);
}
}
Qt::SortOrder DolphinView::sortOrder() const
{
- return fileView()->isReversed() ? Qt::Descending : Qt::Ascending;
+ return m_proxyModel->sortOrder();
}
void DolphinView::goBack()
m_urlNavigator->goHome();
}
-void DolphinView::setURLEditable(bool editable)
+void DolphinView::setUrlEditable(bool editable)
{
- m_urlNavigator->editURL(editable);
+ m_urlNavigator->editUrl(editable);
}
-const Q3ValueList<URLNavigator::HistoryElem> DolphinView::urlHistory(int& index) const
+const Q3ValueList<UrlNavigator::HistoryElem> DolphinView::urlHistory(int& index) const
{
return m_urlNavigator->history(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 fileView()->selectedItems();
+ QItemSelectionModel* selModel = m_iconsView->selectionModel();
+ assert(selModel != 0);
+
+ KFileItemList itemList;
+ if (selModel->hasSelection()) {
+ const QModelIndexList indexList = selModel->selectedIndexes();
+
+ QModelIndexList::const_iterator end = indexList.end();
+ for (QModelIndexList::const_iterator it = indexList.begin(); it != end; ++it) {
+ KFileItem* item = m_dirModel->itemForIndex(*it);
+ if (item != 0) {
+ itemList.append(item);
+ }
+ }
+ }
+ return itemList;
}
-KUrl::List DolphinView::selectedURLs() const
+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();
- KFileItem* item = 0;
- while (it != end) {
- 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 KFileItem* DolphinView::currentFileItem() const
{
- return fileView()->currentFileItem();
+ return 0; // fileView()->currentFileItem();
}
void DolphinView::openContextMenu(KFileItem* fileInfo, const QPoint& pos)
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...
}
if (ok) {
- m_statusBar->setMessage(i18n("Renamed file '%1' to '%2'.").arg(source.fileName(), dest.fileName()),
+ m_statusBar->setMessage(i18n("Renamed file '%1' to '%2'.",source.fileName(), dest.fileName()),
DolphinStatusBar::OperationCompleted);
DolphinCommand command(DolphinCommand::Rename, source, dest);
UndoManager::instance().addCommand(command);
}
else {
- m_statusBar->setMessage(i18n("Renaming of file '%1' to '%2' failed.").arg(source.fileName(), dest.fileName()),
+ m_statusBar->setMessage(i18n("Renaming of file '%1' to '%2' failed.",source.fileName(), dest.fileName()),
DolphinStatusBar::Error);
reload();
}
startDirLister(m_urlNavigator->url(), true);
}
-void DolphinView::slotURLListDropped(QDropEvent* /* event */,
+void DolphinView::slotUrlListDropped(QDropEvent* /* event */,
const KUrl::List& urls,
const KUrl& url)
{
destination = m_urlNavigator->url();
}
else {
- // Check whether the destination URL is a directory. If this is not the
- // case, use the navigator URL as destination (otherwise the destination,
+ // Check whether the destination Url is a directory. If this is not the
+ // case, use the navigator Url as destination (otherwise the destination,
// which represents a file, would be replaced by a copy- or move-operation).
KFileItem fileItem(KFileItem::Unknown, KFileItem::Unknown, destination);
if (!fileItem.isDir()) {
}
}
- Dolphin::mainWin().dropURLs(urls, destination);
+ mainWindow()->dropUrls(urls, destination);
}
void DolphinView::mouseReleaseEvent(QMouseEvent* event)
{
QWidget::mouseReleaseEvent(event);
- Dolphin::mainWin().setActiveView(this);
+ mainWindow()->setActiveView(this);
}
-void DolphinView::slotURLChanged(const KUrl& url)
+DolphinMainWindow* DolphinView::mainWindow() const
+{
+ return m_mainWindow;
+}
+
+void DolphinView::loadDirectory(const KUrl& url)
{
const ViewProperties props(url);
setMode(props.viewMode());
- const bool showHiddenFiles = props.isShowHiddenFilesEnabled();
- setShowHiddenFilesEnabled(showHiddenFiles);
+ const bool showHiddenFiles = props.showHiddenFiles();
+ setShowHiddenFiles(showHiddenFiles);
m_dirLister->setShowingDotFiles(showHiddenFiles);
setSorting(props.sorting());
setSortOrder(props.sortOrder());
startDirLister(url);
-
- // The selectionChanged signal is not emitted when a new view object is
- // 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();
-
- emit signalURLChanged(url);
+ emit urlChanged(url);
}
void DolphinView::triggerIconsViewItem(Q3IconViewItem* item)
((keyboardState & Qt::ControlModifier) > 0);*/
const bool isSelectionActive = false;
if ((item != 0) && !isSelectionActive) {
- // Updating the URL must be done outside the scope of this slot,
+ // 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);
+ QTimer::singleShot(0, this, SLOT(updateUrl()));
+ mainWindow()->setActiveView(this);
}
}
-void DolphinView::triggerDetailsViewItem(Q3ListViewItem* item,
- const QPoint& pos,
- int /* column */)
+void DolphinView::triggerItem(const QModelIndex& index)
{
+ KFileItem* item = m_dirModel->itemForIndex(index);
if (item == 0) {
return;
}
- if (m_detailsView->isOnFilename(item, pos)) {
- // Updating the URL must be done outside the scope of this slot,
- // as listview items will get deleted.
- QTimer::singleShot(0, this, SLOT(updateURL()));
- Dolphin::mainWin().setActiveView(this);
+ if (item->isDir()) {
+ // Prefer the local path over the Url. This assures that the
+ // volume space information is correct. Assuming that the Url is media:/sda1,
+ // and the local path is /windows/C: For the Url the space info is related
+ // to the root partition (and hence wrong) and for the local path the space
+ // info is related to the windows partition (-> correct).
+ //m_dirLister->stop();
+ //m_dirLister->openUrl(item->url());
+ //return;
+
+ const QString localPath(item->localPath());
+ if (localPath.isEmpty()) {
+ setUrl(item->url());
+ }
+ else {
+ setUrl(KUrl(localPath));
+ }
}
else {
- m_detailsView->clearSelection();
+ item->run();
}
}
-void DolphinView::triggerDetailsViewItem(Q3ListViewItem* item)
+void DolphinView::updateUrl()
{
- const QPoint pos(0, item->itemPos());
- triggerDetailsViewItem(item, pos, 0);
-}
-
-void DolphinView::updateURL()
-{
- KFileView* fileView = (m_iconsView != 0) ? static_cast<KFileView*>(m_iconsView) :
- static_cast<KFileView*>(m_detailsView);
+ //KFileView* fileView = (m_iconsView != 0) ? static_cast<KFileView*>(m_iconsView) :
+ // static_cast<KFileView*>(m_iconsView);
- KFileItem* fileItem = fileView->currentFileItem();
+ KFileItem* fileItem = 0; // TODO: fileView->currentFileItem();
if (fileItem == 0) {
return;
}
if (fileItem->isDir()) {
- // Prefer the local path over the URL. This assures that the
- // volume space information is correct. Assuming that the URL is media:/sda1,
- // and the local path is /windows/C: For the URL the space info is related
+ // Prefer the local path over the Url. This assures that the
+ // volume space information is correct. Assuming that the Url is media:/sda1,
+ // and the local path is /windows/C: For the Url the space info is related
// to the root partition (and hence wrong) and for the local path the space
// info is related to the windows partition (-> correct).
const QString localPath(fileItem->localPath());
if (localPath.isEmpty()) {
- setURL(fileItem->url());
+ setUrl(fileItem->url());
}
else {
- setURL(KUrl(localPath));
+ setUrl(KUrl(localPath));
}
}
else {
void DolphinView::slotClear()
{
- fileView()->clearView();
+ //fileView()->clearView();
updateStatusBar();
}
void DolphinView::slotDeleteItem(KFileItem* item)
{
- fileView()->removeItem(item);
+ //fileView()->removeItem(item);
updateStatusBar();
}
{
m_refreshing = true;
- KFileView* view = fileView();
- view->clearView();
+ //KFileView* view = fileView();
+ //view->clearView();
// TODO: in Qt4 the code should get a lot
// simpler and nicer due to Interview...
- if (m_iconsView != 0) {
+ /*if (m_iconsView != 0) {
m_iconsView->beginItemUpdates();
}
- if (m_detailsView != 0) {
- m_detailsView->beginItemUpdates();
- }
+ if (m_iconsView != 0) {
+ m_iconsView->beginItemUpdates();
+ }*/
if (m_showProgress) {
m_statusBar->setProgressText(QString::null);
m_fileCount = 0;
m_folderCount = 0;
- KFileItem* item = 0;
while (it != end) {
- view->insertItem(item);
+ KFileItem* item = *it;
+ //view->insertItem(item);
if (item->isDir()) {
++m_folderCount;
}
updateStatusBar();
- if (m_iconsView != 0) {
+ /*if (m_iconsView != 0) {
// Prevent a flickering of the icon view widget by giving a small
// timeslot to swallow asynchronous update events.
m_iconsView->setUpdatesEnabled(false);
QTimer::singleShot(10, this, SLOT(slotDelayedUpdate()));
}
- if (m_detailsView != 0) {
- m_detailsView->endItemUpdates();
- m_refreshing = false;
- }
-}
-
-void DolphinView::slotDelayedUpdate()
-{
if (m_iconsView != 0) {
- m_iconsView->setUpdatesEnabled(true);
m_iconsView->endItemUpdates();
- }
- m_refreshing = false;
+ m_refreshing = false;
+ }*/
}
void DolphinView::slotInfoMessage(const QString& msg)
m_statusBar->setMessage(msg, DolphinStatusBar::Error);
}
-void DolphinView::slotRefreshItems(const KFileItemList& /* list */)
+void DolphinView::slotGrabActivation()
{
- QTimer::singleShot(0, this, SLOT(reload()));
+ mainWindow()->setActiveView(this);
}
-void DolphinView::slotAddItems(const KFileItemList& list)
+void DolphinView::emitSelectionChangedSignal()
{
- fileView()->addItemList(list);
- fileView()->updateView();
+ emit selectionChanged();
}
-void DolphinView::slotGrabActivation()
+void DolphinView::closeFilterBar()
{
- Dolphin::mainWin().setActiveView(this);
+ m_filterBar->hide();
+ emit showFilterBarChanged(false);
}
void DolphinView::slotContentsMoving(int x, int y)
}
}
-void DolphinView::createView()
-{
- assert(m_iconsView == 0);
- assert(m_detailsView == 0);
-
- switch (m_mode) {
- case IconsView:
- case PreviewsView: {
- const DolphinIconsView::LayoutMode layoutMode = (m_mode == IconsView) ?
- DolphinIconsView::Icons :
- DolphinIconsView::Previews;
- m_iconsView = new DolphinIconsView(this, layoutMode);
- m_topLayout->insertWidget(1, m_iconsView);
- setFocusProxy(m_iconsView);
-
- connect(m_iconsView, SIGNAL(executed(Q3IconViewItem*)),
- this, SLOT(triggerIconsViewItem(Q3IconViewItem*)));
- connect(m_iconsView, SIGNAL(returnPressed(Q3IconViewItem*)),
- this, SLOT(triggerIconsViewItem(Q3IconViewItem*)));
- connect(m_iconsView, SIGNAL(signalRequestActivation()),
- this, SLOT(slotGrabActivation()));
-
- m_iconsView->endItemUpdates();
- m_iconsView->show();
- m_iconsView->setFocus();
- break;
- }
-
- case DetailsView: {
- m_detailsView = new DolphinDetailsView(this);
- m_topLayout->insertWidget(1, m_detailsView);
- setFocusProxy(m_detailsView);
-
- connect(m_detailsView, SIGNAL(executed(Q3ListViewItem*, const QPoint&, int)),
- this, SLOT(triggerDetailsViewItem(Q3ListViewItem*, const QPoint&, int)));
- connect(m_detailsView, SIGNAL(returnPressed(Q3ListViewItem*)),
- this, SLOT(triggerDetailsViewItem(Q3ListViewItem*)));
- connect(m_detailsView, SIGNAL(signalRequestActivation()),
- this, SLOT(slotGrabActivation()));
- m_detailsView->show();
- m_detailsView->setFocus();
- break;
- }
-
- default:
- break;
- }
-
- connect(scrollView(), SIGNAL(contentsMoving(int, int)),
- this, SLOT(slotContentsMoving(int, int)));
-
- startDirLister(m_urlNavigator->url());
-}
-
-KFileView* DolphinView::fileView() const
-{
- return (m_mode == DetailsView) ? static_cast<KFileView*>(m_detailsView) :
- static_cast<KFileView*>(m_iconsView);
-}
-
-Q3ScrollView* DolphinView::scrollView() const
-{
- return (m_mode == DetailsView) ? static_cast<Q3ScrollView*>(m_detailsView) :
- static_cast<Q3ScrollView*>(m_iconsView);
-}
-
-ItemEffectsManager* DolphinView::itemEffectsManager() const
-{
- return (m_mode == DetailsView) ? static_cast<ItemEffectsManager*>(m_detailsView) :
- static_cast<ItemEffectsManager*>(m_iconsView);
-}
-
void DolphinView::startDirLister(const KUrl& url, bool reload)
{
if (!url.isValid()) {
m_statusBar->setMessage(i18n("The location is empty."), DolphinStatusBar::Error);
}
else {
- m_statusBar->setMessage(i18n("The location '%1' is invalid.").arg(location),
+ m_statusBar->setMessage(i18n("The location '%1' is invalid.",location),
DolphinStatusBar::Error);
}
return;
text = i18n("1 Item");
}
else {
- text = i18n("%1 Items").arg(itemCount);
+ text = i18n("%1 Items",itemCount);
}
text += " (";
text += i18n("1 Folder");
}
else {
- text += i18n("%1 Folders").arg(m_folderCount);
+ text += i18n("%1 Folders",m_folderCount);
}
text += ", ";
text += i18n("1 File");
}
else {
- text += i18n("%1 Files").arg(m_fileCount);
+ text += i18n("%1 Files",m_fileCount);
}
text += ")";
// 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()) {
text = i18n("1 Folder selected");
}
else if (folderCount > 1) {
- text = i18n("%1 Folders selected").arg(folderCount);
+ text = i18n("%1 Folders selected",folderCount);
}
if ((fileCount > 0) && (folderCount > 0)) {
const QString sizeText(KIO::convertSize(byteSize));
if (fileCount == 1) {
- text += i18n("1 File selected (%1)").arg(sizeText);
+ text += i18n("1 File selected (%1)",sizeText);
}
else if (fileCount > 1) {
- text += i18n("%1 Files selected (%1)").arg(fileCount).arg(sizeText);
+ text += i18n("%1 Files selected (%1)",fileCount,sizeText);
}
return text;
}
}
+void DolphinView::declareViewActive()
+{
+ mainWindow()->setActiveView( this );
+}
+
void DolphinView::slotChangeNameFilter(const QString& nameFilter)
{
// The name filter of KDirLister does a 'hard' filtering, which
m_dirLister->setNameFilter(adjustedFilter);
m_dirLister->emitChanges();
+}
- // TODO: this is a workaround for QIconView: the item position
- // stay as they are by filtering, only an inserting of an item
- // results to an automatic adjusting of the item position. In Qt4/KDE4
- // this workaround should get obsolete due to Interview.
- KFileView* view = fileView();
- if (view == m_iconsView) {
- KFileItem* first = view->firstFileItem();
- if (first != 0) {
- view->removeItem(first);
- view->insertItem(first);
- }
+void DolphinView::applyModeToView()
+{
+ m_iconsView->setSelectionMode(QAbstractItemView::ExtendedSelection);
+
+ // TODO: the following code just tries to test some QListView capabilities
+ switch (m_mode) {
+ case IconsView:
+ m_iconsView->setViewMode(QListView::IconMode);
+ m_iconsView->setSpacing(32);
+ // m_iconsView->setAlternatingRowColors(false);
+ // m_iconsView->setGridSize(QSize(128, 64));
+ break;
+
+ case DetailsView:
+ m_iconsView->setViewMode(QListView::ListMode);
+ m_iconsView->setSpacing(0);
+ // m_iconsView->setAlternatingRowColors(true);
+ // m_iconsView->setGridSize(QSize(256, 24));
+ break;
}
}
-bool DolphinView::isFilterBarVisible()
+int DolphinView::columnIndex(Sorting sorting) const
{
- return m_filterBar->isVisible();
+ int index = 0;
+ switch (sorting) {
+ case SortByName: index = KDirModel::Name; break;
+ case SortBySize: index = KDirModel::Size; break;
+ case SortByDate: index = KDirModel::ModifiedTime; break;
+ default: assert(false);
+ }
+ return index;
+}
+
+void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags)
+{
+ QItemSelectionModel* selectionModel = m_iconsView->selectionModel();
+ const QAbstractItemModel* itemModel = selectionModel->model();
+
+ const QModelIndex topLeft = itemModel->index(0, 0);
+ const QModelIndex bottomRight = itemModel->index(itemModel->rowCount() - 1,
+ itemModel->columnCount() - 1);
+
+ QItemSelection selection(topLeft, bottomRight);
+ selectionModel->select(selection, flags);
}
#include "dolphinview.moc"