summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Reher <tde@4reher.org>2021-02-13 17:17:13 -0800
committerVincent Reher <tde@4reher.org>2021-02-15 10:01:34 -0800
commit21d5444633f76704576e09707df2e50a823994a7 (patch)
tree22def09611933a5187ada4603a872255f5ddc957
parentc3df40ca4a7af5171a1c8cde39321892fc930b07 (diff)
downloadtdebase-21d5444633f76704576e09707df2e50a823994a7.tar.gz
tdebase-21d5444633f76704576e09707df2e50a823994a7.zip
Persist state resulting from new sorting actions as KonqListViewSettings.
More code cleanup / reorganization. Signed-off-by: Vincent Reher <tde@4reher.org>
-rw-r--r--konqueror/listview/konq_listview.cpp255
-rw-r--r--konqueror/listview/konq_listview.h18
-rw-r--r--konqueror/listview/konq_listview.kcfg22
-rw-r--r--konqueror/listview/konq_listviewitems.cpp3
-rw-r--r--konqueror/listview/konq_listviewitems.h6
5 files changed, 212 insertions, 92 deletions
diff --git a/konqueror/listview/konq_listview.cpp b/konqueror/listview/konq_listview.cpp
index a0067d3d9..f74bb8aa9 100644
--- a/konqueror/listview/konq_listview.cpp
+++ b/konqueror/listview/konq_listview.cpp
@@ -17,7 +17,7 @@
Boston, MA 02110-1301, USA.
*/
-//-Not needed right now: define DEBUG_SORTFUNCS
+#define DEBUG_SORTFUNCS 0
#include "konq_listview.h"
#include "konq_textviewwidget.h"
@@ -270,7 +270,7 @@ KonqListView::KonqListView( TQWidget *parentWidget, TQObject *parent, const char
m_mimeTypeResolver = new KMimeTypeResolver<KonqBaseListViewItem,KonqListView>(this);
setXMLFile( xmlFile );
-
+
setupActions();
m_pListView->confColumns.resize( 11 );
@@ -287,6 +287,7 @@ KonqListView::KonqListView( TQWidget *parentWidget, TQObject *parent, const char
// Note: File Type is in fact the mimetype comment. We use UDS_FILE_TYPE but that's not what we show in fact :/
m_pListView->confColumns[10].setData(I18N_NOOP("File Type"),"Type",TDEIO::UDS_FILE_TYPE,m_paShowType);
+
connect( m_pListView, TQT_SIGNAL( selectionChanged() ),
m_extension, TQT_SLOT( updateActions() ) );
connect( m_pListView, TQT_SIGNAL( selectionChanged() ),
@@ -541,24 +542,26 @@ void KonqListView::slotColumnToggled()
slotHeaderSizeChanged();
}
+//------------------------------------------------------------------------------
+//--- Begin: listview sorting enhancements
+//------------------------------------------------------------------------------
+
void KonqListView::slotHeaderClicked(int sec)
{
kdDebug(1202)<<"section: "<<sec<<" clicked"<<endl;
- //----------------------------------------
- //--- Begin: listview sorting enhancements
- //----------------------------------------
-
/* Notes
- * I think 'section' represents the left-to-right offset of a VISIBLE column
*
- * I think this subroutine does not trigger any sorting by itself but rather
- * is called AFTER the sort has already been done, maybe to ensure that
- * the configuration file is updated!
+ * (1) I think 'section' represents the left-to-right offset of a
+ * VISIBLE column
+ *
+ * (2) I think this subroutine does not trigger any sorting by
+ * itself but rather is called AFTER the sort has already
+ * been done, maybe to ensure that the configuration file
+ * is updated!
*/
- /* Original code removed:
-
+ /* Original code moved to function DisplayColumn_Name():
int clickedColumn(-1);
for (uint i=0; i<m_pListView->NumberOfAtoms; i++)
if (m_pListView->confColumns[i].displayInColumn==sec) clickedColumn=i;
@@ -569,45 +572,14 @@ void KonqListView::slotHeaderClicked(int sec)
nameOfSortColumn="FileName";
else
nameOfSortColumn=m_pListView->confColumns[clickedColumn].desktopFileName;
-
*/
-
TQString nameOfSortColumn = DisplayColumn_Name(sec) ;
- #ifdef DEBUG_SORTFUNCS
- kdWarning()<<"section: "<<sec<<" clicked"<<endl;
- #endif
-
- if ( sec != SortColumnIndex_Alternate ) {
- #ifdef DEBUG_SORTFUNCS
- kdWarning()
- << "KonqListView::slotHeaderClicked - changed alternate sort column"
- << " FROM '" << SortColumnName_Alternate
- << "' ( column " << SortColumnIndex_Alternate << " )" << endl
- ;
- #endif
-
- SortColumnIndex_Alternate = sec ;
- SortColumnName_Alternate = nameOfSortColumn ;
-
- #ifdef DEBUG_SORTFUNCS
- kdWarning()
- << "KonqListView::slotHeaderClicked - changed alternate sort column"
- << "TO '" << SortColumnName_Alternate
- << "' ( column " << SortColumnIndex_Alternate << " )" << endl
- ;
- #endif
- }
-
- //----------------------------------------
- //--- End: listview sorting enhancements
- //----------------------------------------
-
if (nameOfSortColumn!=m_pListView->sortedByColumn)
{
m_pListView->sortedByColumn=nameOfSortColumn;
m_pListView->setAscending(TRUE);
- #ifdef DEBUG_SORTFUNCS
+ #if DEBUG_SORTFUNCS > 1
kdWarning()
<< "KonqListView::slotHeaderClicked - changed sort column to # "
<< sec << endl
@@ -617,32 +589,74 @@ void KonqListView::slotHeaderClicked(int sec)
else
{
m_pListView->setAscending(!m_pListView->ascending());
- #ifdef DEBUG_SORTFUNCS
+ #if DEBUG_SORTFUNCS > 1
kdWarning()
- << "KonqListView::slotHeaderClicked - changed sort order of column #"
+ << "KonqListView::slotHeaderClicked - changed sort order of column # "
<< sec << endl
;
#endif
}
+ /*
+ This function stores/utilizes settings stored on disk in:
+ config/konquerorrc/[ListView_file]
+ Previous konq_listview settings:
+ SortOrder, SortBy
+ New settings that were added with konq_listview++:
+ PrimarySortOrder,
+ AlternateSortCol, AlternateSortIndex, AlternateSortOrder
+ */
+
KonqListViewSettings config( m_pListView->url().protocol() );
config.readConfig();
+
+ if ( nameOfSortColumn == SortColumnName_Primary )
+ {
+ SortColumnName_Primary = nameOfSortColumn ;
+ SortColumnIndex_Primary = sec ;
+ SortColumnOrder_Primary = m_pListView->ascending() ;
+ config.setPrimarySortOrder( m_pListView->ascending() );
+ #if DEBUG_SORTFUNCS > 0
+ kdWarning()
+ << "KonqListView::slotHeaderClicked - sort column "
+ << " '" << SortColumnName_Primary << "' ( column # "
+ << SortColumnIndex_Primary << " ) is PRIMARY" << endl
+ ;
+ #endif
+
+ } else {
+ SortColumnName_Alternate = nameOfSortColumn ;
+ config.setAlternateSortCol( nameOfSortColumn );
+ SortColumnIndex_Alternate = sec ;
+ config.setAlternateSortIndex( sec );
+ SortColumnOrder_Alternate = m_pListView->ascending() ;
+ config.setAlternateSortOrder( m_pListView->ascending() );
+ #if DEBUG_SORTFUNCS > 0
+ kdWarning()
+ << "KonqListView::slotHeaderClicked - sort column "
+ << " '" << SortColumnName_Alternate << "' ( column # "
+ << SortColumnIndex_Alternate << " ) is ALTERNATE" << endl
+ ;
+ #endif
+ }
+ //----------------------------------------
+ //--- End: listview sorting enhancements
+ //----------------------------------------
+
config.setSortBy( nameOfSortColumn );
config.setSortOrder( m_pListView->ascending() );
config.writeConfig();
}
-//------------------------------------------------------------------------------
-//--- Begin: listview sorting enhancements
-//------------------------------------------------------------------------------
-
TQString KonqListView::DisplayColumn_Name( int DisplayColumn_Offset)
{
+ /* Given a column's display offset, return its name */
int(ColumnIndex) = -1 ;
- for (uint i=0; i<m_pListView->NumberOfAtoms; i++)
+ for (uint i=0; i<m_pListView->NumberOfAtoms; i++) {
if (m_pListView->confColumns[i].displayInColumn == DisplayColumn_Offset)
- ColumnIndex=i;
- #ifdef DEBUG_SORTFUNCS
+ ColumnIndex = i;
+ }
+ #if DEBUG_SORTFUNCS > 2
kdWarning() << "What is name of display column #"
<< DisplayColumn_Offset << "?" << endl ;
if (ColumnIndex == -1)
@@ -654,9 +668,30 @@ TQString KonqListView::DisplayColumn_Name( int DisplayColumn_Offset)
return( m_pListView->confColumns[ColumnIndex].desktopFileName ) ;
}
-void KonqListView::SortListView(uint which)
+int KonqListView::DisplayColumn_Index( TQString DisplayColumn_Name )
{
+ /* Given a column's name, return its display offset */
+ int(ColumnIndex) = -1 ;
+ TQString ColumnName ;
+ for (uint i=0; i<m_pListView->NumberOfAtoms; i++) {
+ ColumnName = m_pListView->confColumns[i].desktopFileName ;
+ if ( ColumnName == DisplayColumn_Name )
+ ColumnIndex = m_pListView->confColumns[i].displayInColumn;
+ }
+ #if DEBUG_SORTFUNCS > 2
+ kdWarning() << "What is offset of display column "
+ << DisplayColumn_Name << "?" << endl ;
+ if (ColumnIndex == -1)
+ kdWarning() << "Answer: Not found, forced to 0" << endl;
+ else
+ kdWarning() << "Answer: " << ColumnIndex << endl;
+ #endif
+ if (ColumnIndex == -1) return 0 ;
+ return( ColumnIndex ) ;
+}
+void KonqListView::SortListView(uint which)
+{
TQString SortColumnName_Current = m_pListView->sortedByColumn ;
int SortColumnIndex_Current ;
@@ -665,6 +700,26 @@ void KonqListView::SortListView(uint which)
uint SortOrder ;
+ /*
+ This function stores/utilizes settings stored on disk in:
+ config/konquerorrc/[ListView_file]
+ New settings that were added with konq_listview++:
+ PrimarySortOrder,
+ AlternateSortCol, AlternateSortIndex, AlternateSortOrder
+ */
+
+ KonqListViewSettings config( m_pListView->url().protocol() );
+ config.readConfig();
+
+ // Set KonqListView variables from respective settings
+ SortColumnOrder_Primary = config.primarySortOrder();
+ SortColumnName_Alternate = config.alternateSortCol();
+ SortColumnOrder_Alternate = config.alternateSortOrder();
+ SortColumnIndex_Alternate = config.alternateSortIndex();
+ /* Alternative for determining column index without storing it in config:
+ SortColumnIndex_Alternate = DisplayColumn_Index( SortColumnName_Alternate ) ;
+ */
+
switch( which ) {
//-----------------------------------------------------------------------
@@ -673,30 +728,40 @@ void KonqListView::SortListView(uint which)
case 1 :
- if ( SortColumnName_Primary == SortColumnName_Current ) {
- #ifdef DEBUG_SORTFUNCS
- kdWarning() << "Switching column sort from primary to alternate" << endl ;
- #endif
- SortColumnName_Next = SortColumnName_Alternate ;
- SortColumnIndex_Next = SortColumnIndex_Alternate ;
+ if ( SortColumnName_Current == SortColumnName_Primary )
+ {
+ #if DEBUG_SORTFUNCS > 1
+ kdWarning() << "KonqListView::SortListView - "
+ << "Switching sort column from primary to alternate" << endl
+ ;
+ #endif
+ SortColumnName_Next = SortColumnName_Alternate ;
+ SortColumnIndex_Next = SortColumnIndex_Alternate ;
+ SortOrder = SortColumnOrder_Alternate ;
+ // Previously set sort order of alternate sort column is preserved
}
- else {
- #ifdef DEBUG_SORTFUNCS
- kdWarning() << "Switching column sort from alternate to primary" << endl ;
- #endif
- SortColumnName_Next = SortColumnName_Primary ;
- SortColumnIndex_Next = SortColumnIndex_Primary ;
+ else
+ {
+ #if DEBUG_SORTFUNCS > 1
+ kdWarning() << "KonqListView::SortListView - "
+ << "Switching sort column from alternate to primary" << endl ;
+ #endif
+ SortColumnName_Next = SortColumnName_Primary ;
+ SortColumnIndex_Next = SortColumnIndex_Primary ;
+ SortOrder = SortColumnOrder_Primary ;
+ // Previously set sort order of primary sort column is preserved
}
- SortOrder = 1 ;
- m_pListView->setSorting( SortColumnIndex_Next, SortOrder ) ;
m_pListView->sortedByColumn = SortColumnName_Next ;
+ config.setSortBy( SortColumnName_Next );
- #ifdef DEBUG_SORTFUNCS
- kdWarning()
- << "KonqListView::SortListView - changed sort column FROM "
- << SortColumnName_Current << " TO " << SortColumnName_Next
- << " [" << SortColumnIndex_Next << "]" << endl
+ // Set up sort parameters
+ m_pListView->setSorting( SortColumnIndex_Next, SortOrder ) ;
+
+ #if DEBUG_SORTFUNCS > 0
+ kdWarning() << "KonqListView::SortListView - Changed sort column FROM "
+ << SortColumnName_Current << "[" << SortColumnIndex_Current << "] TO "
+ << SortColumnName_Next << " [" << SortColumnIndex_Next << "]" << endl
;
#endif
@@ -708,15 +773,35 @@ void KonqListView::SortListView(uint which)
case 2 :
+ SortOrder = !m_pListView->ascending() ;
+
if ( SortColumnName_Primary == SortColumnName_Current )
- SortColumnIndex_Current = SortColumnIndex_Primary ;
+ {
+ #if DEBUG_SORTFUNCS > 1
+ kdWarning() << "KonqListView::SortListView - "
+ << "Reversing sort order of primary sort column" << endl ;
+ #endif
+ SortColumnIndex_Current = SortColumnIndex_Primary ;
+ SortColumnOrder_Primary = SortOrder ;
+ config.setPrimarySortOrder( SortOrder ) ;
+ }
else
- SortColumnIndex_Current = SortColumnIndex_Alternate ;
+ {
+ #if DEBUG_SORTFUNCS > 1
+ kdWarning() << "KonqListView::SortListView - "
+ << "Reversing sort order of alternate sort column" << endl ;
+ #endif
+ SortColumnIndex_Current = SortColumnIndex_Alternate ;
+ SortColumnOrder_Alternate = SortOrder ;
+ config.setAlternateSortOrder( SortOrder ) ;
+ }
+ m_pListView->setAscending(SortOrder) ;
+ config.setSortOrder( SortOrder );
- SortOrder = !m_pListView->ascending() ;
+ // Set up sort parameters
m_pListView->setSorting( SortColumnIndex_Current, SortOrder ) ;
- #ifdef DEBUG_SORTFUNCS
+ #if DEBUG_SORTFUNCS > 0
kdWarning()
<< "KonqListView::SortListView - Reversing sort on column "
<< SortColumnName_Current << endl
@@ -726,9 +811,11 @@ void KonqListView::SortListView(uint which)
break ;
}
- // Do actual sorting and remember the order
+ // Do actual sorting
m_pListView->sort();
- m_pListView->setAscending(SortOrder) ;
+
+ // Store settings
+ config.writeConfig();
}
void KonqListView::slotSortAlternate()
@@ -932,6 +1019,16 @@ void KonqListView::setupActions()
"reverse_sort_order"
);
+ /*
+ The slot functions associated with the next 3 TDEToggleActions
+ utilize some new boolean settings stored on disk in:
+ config/konqlistviewrc:[Settings]/
+ New settings that were added with konq_listview++:
+ GroupDirsFirst (comparable to konq_iconview SortDirsFirst)
+ GroupHiddenFirst
+ DictionaryOrderSort
+ */
+
m_paDisplay_Directories_1st = new TDEToggleAction(
i18n("Group &Directories First"), 0, this,
TQT_SLOT(slot_Toggle_Display_Directories_1st()), actionCollection(),
diff --git a/konqueror/listview/konq_listview.h b/konqueror/listview/konq_listview.h
index 22c1208c2..f1a17dbe8 100644
--- a/konqueror/listview/konq_listview.h
+++ b/konqueror/listview/konq_listview.h
@@ -175,21 +175,19 @@ private:
TDEAction *m_paSortReverse; // triggers slotSortReverse()
// Variables utilized in SortListView()
- TQString SortColumnName_Primary = "FileName" ; // by definition
- int SortColumnIndex_Primary = 0 ; // always!
- TQString SortColumnName_Alternate ; // reset in slotHeaderClicked()
- int SortColumnIndex_Alternate = 1 ; // reset in slotHeaderClicked()
+ TQString SortColumnName_Primary = "FileName" ; // by definition
+ int SortColumnIndex_Primary = 0 ; // always!
+ int SortColumnOrder_Primary = 1 ; // modified in SortListView()
+ TQString SortColumnName_Alternate ;
+ int SortColumnIndex_Alternate ; // modified in slotHeaderClicked()
+ int SortColumnOrder_Alternate ; // modified in SortListView()
// Specialized sorting functions
void SortListView(uint which); // called by slotSort*()
- TQString DisplayColumn_Name( int DisplayColumn_Offset) ;
-
- //----------------------------------------
- //--- Begin: listview sorting enhancements
- //----------------------------------------
+ TQString DisplayColumn_Name( int DisplayColumn_Offset ) ;
+ int DisplayColumn_Index( TQString DisplayColumn_Name ) ;
// User action-response handlers
-
TDEToggleAction *m_paDisplay_Directories_1st;
// triggers slot_Toggle_Display_Directories_1st()
TDEToggleAction *m_paDisplay_Hidden_1st;
diff --git a/konqueror/listview/konq_listview.kcfg b/konqueror/listview/konq_listview.kcfg
index bce9798a6..8d1496b0f 100644
--- a/konqueror/listview/konq_listview.kcfg
+++ b/konqueror/listview/konq_listview.kcfg
@@ -19,6 +19,28 @@
<label>Sort Order</label>
<whatsthis></whatsthis>
</entry>
+ <!-- Begin: listview sorting enhancements -->
+ <entry key="PrimarySortOrder" type="Bool">
+ <default>true</default>
+ <label>Primary sort column sorting order</label>
+ <whatsthis></whatsthis>
+ </entry>
+ <entry key="AlternateSortCol" type="String">
+ <default>Date</default>
+ <label>Alternate sort column name (usually FileName)</label>
+ <whatsthis></whatsthis>
+ </entry>
+ <entry key="AlternateSortIndex" type="Int">
+ <default>0</default>
+ <label>Alternate sort column offset (click to set)</label>
+ <whatsthis></whatsthis>
+ </entry>
+ <entry key="AlternateSortOrder" type="Bool">
+ <default>true</default>
+ <label>Alternate sort column sorting order</label>
+ <whatsthis></whatsthis>
+ </entry>
+ <!-- End: listview sorting enhancements -->
<entry key="FileNameColumnWidth" type="Int">
<default code="true">25 * TDEApplication::kApplication()->fontMetrics().width( "m" )</default>
<label>Width of the FileName Column</label>
diff --git a/konqueror/listview/konq_listviewitems.cpp b/konqueror/listview/konq_listviewitems.cpp
index 366e5912f..0bdc3cd43 100644
--- a/konqueror/listview/konq_listviewitems.cpp
+++ b/konqueror/listview/konq_listviewitems.cpp
@@ -488,6 +488,7 @@ KonqBaseListViewItem::KonqBaseListViewItem(KonqBaseListViewWidget *_listViewWidg
KonqBaseListViewItem::KonqBaseListViewItem(KonqBaseListViewWidget *_listViewWidget, KonqBaseListViewItem *_parent, KFileItem* _fileitem)
:TDEListViewItem(_parent)
,sortChar(0)
+,sortString() // listview sorting enhancement
,m_bDisabled(false)
,m_bActive(false)
,m_fileitem(_fileitem)
@@ -504,6 +505,8 @@ KonqBaseListViewItem::~KonqBaseListViewItem()
if (m_pListViewWidget->m_selected)
m_pListViewWidget->m_selected->removeRef(this);
+
+ // FIXME: Newbie questiion: do I need to somehow "free" sortString?
}
TQRect KonqBaseListViewItem::rect() const
diff --git a/konqueror/listview/konq_listviewitems.h b/konqueror/listview/konq_listviewitems.h
index 49248c8db..8ce22507b 100644
--- a/konqueror/listview/konq_listviewitems.h
+++ b/konqueror/listview/konq_listviewitems.h
@@ -53,7 +53,7 @@ class KonqBaseListViewItem : public TDEListViewItem
virtual void setDisabled( bool disabled ) { m_bDisabled = disabled; }
virtual void setActive ( bool active ) { m_bActive = active; }
virtual int compare( TQListViewItem* i, int col, bool ascending ) const;
-
+
int state() const
{
if (m_bDisabled)
@@ -65,7 +65,7 @@ class KonqBaseListViewItem : public TDEListViewItem
/** For KonqMimeTypeResolver */
TQRect rect() const;
-
+
protected:
short int sortChar;
//---------------------------------------
@@ -77,7 +77,7 @@ class KonqBaseListViewItem : public TDEListViewItem
//---------------------------------------
bool m_bDisabled;
bool m_bActive;
-
+
/** Pointer to the file item in KDirLister's list
* Don't use this unless you absolutely have to! */
KFileItem* m_fileitem;