Commit 685cb7a2 authored by Peter Penz's avatar Peter Penz
Browse files

Additionally to sorting by name, size and date it is now possible to sort by...

Additionally to sorting by name, size and date it is now possible to sort by permissions, owner and group.

svn path=/trunk/playground/utils/dolphin/; revision=631058
parent 83ba38ab
......@@ -21,6 +21,7 @@
#include "dolphindetailsview.h"
#include "dolphinmainwindow.h"
#include "dolphinsortfilterproxymodel.h"
#include "dolphinview.h"
#include "viewproperties.h"
......@@ -142,33 +143,21 @@ void DolphinDetailsView::synchronizeSortingState(int column)
// The sorting has already been changed in QTreeView if this slot is
// invoked, but Dolphin was not informed about this. This is bypassed by changing
// the sorting and sort order to a temporary other value and readjust it again.
const bool update = (column == KDirModel::Name) || (column == KDirModel::Size) ||
(column == KDirModel::ModifiedTime);
if (update) {
DolphinView::Sorting sorting = DolphinView::SortByName;
switch (column) {
case KDirModel::Size: sorting = DolphinView::SortBySize; break;
case KDirModel::ModifiedTime: sorting = DolphinView::SortByDate; break;
case KDirModel::Name:
default: break;
}
const Qt::SortOrder sortOrder = header()->sortIndicatorOrder();
// temporary adjust the sorting and sort order to different values...
const DolphinView::Sorting tempSorting = (sorting == DolphinView::SortByName) ?
DolphinView::SortBySize :
DolphinView::SortByName;
m_dolphinView->setSorting(tempSorting);
const Qt::SortOrder tempSortOrder = (sortOrder == Qt::Ascending) ?
Qt::Descending : Qt::Ascending;
m_dolphinView->setSortOrder(tempSortOrder);
// ... so that setting them again results in storing the new setting.
m_dolphinView->setSorting(sorting);
m_dolphinView->setSortOrder(sortOrder);
}
DolphinView::Sorting sorting = DolphinSortFilterProxyModel::sortingForColumn(column);
const Qt::SortOrder sortOrder = header()->sortIndicatorOrder();
// temporary adjust the sorting and sort order to different values...
const DolphinView::Sorting tempSorting = (sorting == DolphinView::SortByName) ?
DolphinView::SortBySize :
DolphinView::SortByName;
m_dolphinView->setSorting(tempSorting);
const Qt::SortOrder tempSortOrder = (sortOrder == Qt::Ascending) ?
Qt::Descending : Qt::Ascending;
m_dolphinView->setSortOrder(tempSortOrder);
// ... so that setting them again results in storing the new setting.
m_dolphinView->setSorting(sorting);
m_dolphinView->setSortOrder(sortOrder);
}
#include "dolphindetailsview.moc"
......@@ -256,6 +256,15 @@ void DolphinMainWindow::slotSortingChanged(DolphinView::Sorting sorting)
case DolphinView::SortByDate:
action = actionCollection()->action("by_date");
break;
case DolphinView::SortByPermissions:
action = actionCollection()->action("by_permissions");
break;
case DolphinView::SortByOwner:
action = actionCollection()->action("by_owner");
break;
case DolphinView::SortByGroup:
action = actionCollection()->action("by_group");
break;
default:
break;
}
......@@ -635,6 +644,21 @@ void DolphinMainWindow::sortByDate()
m_activeView->setSorting(DolphinView::SortByDate);
}
void DolphinMainWindow::sortByPermissions()
{
m_activeView->setSorting(DolphinView::SortByPermissions);
}
void DolphinMainWindow::sortByOwner()
{
m_activeView->setSorting(DolphinView::SortByOwner);
}
void DolphinMainWindow::sortByGroup()
{
m_activeView->setSorting(DolphinView::SortByGroup);
}
void DolphinMainWindow::toggleSortOrder()
{
const Qt::SortOrder order = (m_activeView->sortOrder() == Qt::Ascending) ?
......@@ -1035,10 +1059,25 @@ void DolphinMainWindow::setupActions()
sortByDate->setText(i18n("By Date"));
connect(sortByDate, SIGNAL(triggered()), this, SLOT(sortByDate()));
KToggleAction* sortByPermissions = actionCollection()->add<KToggleAction>("by_permissions");
sortByPermissions->setText(i18n("By Permissions"));
connect(sortByPermissions, SIGNAL(triggered()), this, SLOT(sortByPermissions()));
KToggleAction* sortByOwner = actionCollection()->add<KToggleAction>("by_owner");
sortByOwner->setText(i18n("By Owner"));
connect(sortByOwner, SIGNAL(triggered()), this, SLOT(sortByOwner()));
KToggleAction* sortByGroup = actionCollection()->add<KToggleAction>("by_group");
sortByGroup->setText(i18n("By Group"));
connect(sortByGroup, SIGNAL(triggered()), this, SLOT(sortByGroup()));
QActionGroup* sortGroup = new QActionGroup(this);
sortGroup->addAction(sortByName);
sortGroup->addAction(sortBySize);
sortGroup->addAction(sortByDate);
sortGroup->addAction(sortByPermissions);
sortGroup->addAction(sortByOwner);
sortGroup->addAction(sortByGroup);
KToggleAction* sortDescending = actionCollection()->add<KToggleAction>("descending");
sortDescending->setText(i18n("Descending"));
......
......@@ -217,6 +217,15 @@ private slots:
/** The sorting of the current view should be done by the date. */
void sortByDate();
/** The sorting of the current view should be done by the permissions. */
void sortByPermissions();
/** The sorting of the current view should be done by the owner. */
void sortByOwner();
/** The sorting of the current view should be done by the group. */
void sortByGroup();
/** Switches between an ascending and descending sorting order. */
void toggleSortOrder();
......
......@@ -24,17 +24,23 @@
#include <kdirmodel.h>
#include <kfileitem.h>
static const int dolphinMapSize = 3;
static const int dolphinMapSize = 6;
static int dolphinViewToDirModelColumn[] = {
KDirModel::Name, // DolphinView::SortByName
KDirModel::Size, // DolphinView::SortBySize
KDirModel::ModifiedTime // DolphinView::SortByDate
KDirModel::Name, // DolphinView::SortByName
KDirModel::Size, // DolphinView::SortBySize
KDirModel::ModifiedTime, // DolphinView::SortByDate
KDirModel::Permissions, // DolphinView::SortByPermissions
KDirModel::Owner, // DolphinView::SortByOwner
KDirModel::Group // DolphinView::SortByGroup
};
static DolphinView::Sorting dirModelColumnToDolphinView[] = {
DolphinView::SortByName, // KDirModel::Name
DolphinView::SortBySize, // KDirModel::Size
DolphinView::SortByDate // KDirModel::ModifiedTime
DolphinView::SortByName, // KDirModel::Name
DolphinView::SortBySize, // KDirModel::Size
DolphinView::SortByDate, // KDirModel::ModifiedTime
DolphinView::SortByPermissions, // KDirModel::Permissions
DolphinView::SortByOwner, // KDirModel::Owner
DolphinView::SortByGroup // KDirModel::Group
};
......@@ -81,6 +87,14 @@ void DolphinSortFilterProxyModel::sort(int column, Qt::SortOrder sortOrder)
QSortFilterProxyModel::sort(column, sortOrder);
}
DolphinView::Sorting DolphinSortFilterProxyModel::sortingForColumn(int column)
{
if ((column >= 0) && (column <= dolphinMapSize)) {
return dirModelColumnToDolphinView[column];
}
return DolphinView::SortByName;
}
bool DolphinSortFilterProxyModel::lessThan(const QModelIndex& left,
const QModelIndex& right) const
{
......
......@@ -61,6 +61,13 @@ public:
virtual void sort(int column,
Qt::SortOrder order = Qt::AscendingOrder);
/**
* Helper method to get the DolphinView::Sorting type for a given
* column \a column. If the column is smaller 0 or greater than the
* available columns, DolphinView::SortByName is returned.
*/
static DolphinView::Sorting sortingForColumn(int column);
protected:
virtual bool lessThan(const QModelIndex& left,
const QModelIndex& right) const;
......
......@@ -26,6 +26,9 @@
<Action name="by_name" />
<Action name="by_size" />
<Action name="by_date" />
<Action name="by_permissions" />
<Action name="by_owner" />
<Action name="by_group" />
<Separator/>
<Action name="descending" />
</Menu>
......
......@@ -94,9 +94,12 @@ public:
enum Sorting
{
SortByName = 0,
SortBySize = 1,
SortByDate = 2,
MaxSortEnum = SortByDate
SortBySize,
SortByDate,
SortByPermissions,
SortByOwner,
SortByGroup,
MaxSortEnum = SortByGroup
};
DolphinView(DolphinMainWindow* mainwindow,
......
......@@ -22,6 +22,7 @@
#include "viewpropsprogressinfo.h"
#include "dolphinview.h"
#include "dolphinsettings.h"
#include "dolphinsortfilterproxymodel.h"
#include "generalsettings.h"
#include "viewproperties.h"
......@@ -78,14 +79,10 @@ ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) :
m_sorting->addItem("By Name");
m_sorting->addItem("By Size");
m_sorting->addItem("By Date");
int sortingIdx = 0;
switch (m_viewProps->sorting()) {
case DolphinView::SortByName: sortingIdx = 0; break;
case DolphinView::SortBySize: sortingIdx = 1; break;
case DolphinView::SortByDate: sortingIdx = 2; break;
default: break;
}
m_sorting->setCurrentIndex(sortingIdx);
m_sorting->addItem("By Permissions");
m_sorting->addItem("By Owner");
m_sorting->addItem("By Group");
m_sorting->setCurrentIndex(m_viewProps->sorting());
QLabel* sortOrderLabel = new QLabel(i18n("Sort order:"), propsBox);
m_sortOrder = new QComboBox(propsBox);
......@@ -172,12 +169,7 @@ void ViewPropertiesDialog::slotViewModeChanged(int index)
void ViewPropertiesDialog::slotSortingChanged(int index)
{
DolphinView::Sorting sorting = DolphinView::SortByName;
switch (index) {
case 1: sorting = DolphinView::SortBySize; break;
case 2: sorting = DolphinView::SortByDate; break;
default: break;
}
const DolphinView::Sorting sorting = DolphinSortFilterProxyModel::sortingForColumn(index);
m_viewProps->setSorting(sorting);
m_isDirty = true;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment