25 #include <tdeaction.h>
26 #include <tdeapplication.h>
28 #include <tdeglobal.h>
29 #include <tdelocale.h>
30 #include <kstandarddirs.h>
32 #include "config-tdefile.h"
33 #include "tdefileview.h"
35 #ifdef Unsorted // the "I hate X.h" modus
39 TQDir::SortSpec KFileView::defaultSortSpec =
static_cast<TQDir::SortSpec
>(TQDir::Name | TQDir::IgnoreCase | TQDir::DirsFirst);
41 class KFileView::KFileViewPrivate
58 TQGuardedPtr<TDEActionCollection> actions;
63 KFileView::KFileView()
65 d =
new KFileViewPrivate();
66 m_sorting = KFileView::defaultSortSpec;
69 sig->setName(
"view-signaller");
76 selection_mode = KFile::Single;
77 m_viewName = i18n(
"Unknown View");
79 myOnlyDoubleClickSelectsFiles =
false;
80 m_itemList.setAutoDelete(
false );
87 delete m_selectedList;
90 void KFileView::setParentView(
KFileView *parent)
93 TQObject::connect(sig, TQT_SIGNAL( activatedMenu(
const KFileItem *,
95 parent->sig, TQT_SIGNAL( activatedMenu(
const KFileItem *,
97 TQObject::connect(sig, TQT_SIGNAL( dirActivated(
const KFileItem *)),
98 parent->sig, TQT_SIGNAL( dirActivated(
const KFileItem*)));
99 TQObject::connect(sig, TQT_SIGNAL( fileSelected(
const KFileItem *)),
100 parent->sig, TQT_SIGNAL( fileSelected(
const KFileItem*)));
101 TQObject::connect(sig, TQT_SIGNAL( fileHighlighted(
const KFileItem *) ),
102 parent->sig,TQT_SIGNAL(fileHighlighted(
const KFileItem*)));
103 TQObject::connect(sig, TQT_SIGNAL( sortingChanged( TQDir::SortSpec ) ),
104 parent->sig, TQT_SIGNAL(sortingChanged( TQDir::SortSpec)));
105 TQObject::connect(sig, TQT_SIGNAL( dropped(
const KFileItem *, TQDropEvent*,
const KURL::List&) ),
106 parent->sig, TQT_SIGNAL(dropped(
const KFileItem *, TQDropEvent*,
const KURL::List&)));
112 if (!( viewMode() & Files ) && i->isFile())
115 if (!( viewMode() & Directories ) && i->isDir())
126 void qt_qstring_stats();
134 for (KFileItemListIterator it(list); (tmp = it.current()); ++it)
153 m_sorting = new_sort;
164 void KFileView::sortReversed()
168 setSorting( static_cast<TQDir::SortSpec>( spec ^ TQDir::Reversed ) );
172 int KFileView::compareItems(
const KFileItem *fi1,
const KFileItem *fi2)
const
174 static const TQString &dirup = TDEGlobal::staticQString(
"..");
176 bool keepFirst =
false;
177 bool dirsFirst = ((m_sorting & TQDir::DirsFirst) == TQDir::DirsFirst);
183 if ( fi1->name() == dirup ) {
185 keepFirst = dirsFirst;
187 else if ( fi2->name() == dirup ) {
189 keepFirst = dirsFirst;
193 if ( fi1->isDir() != fi2->isDir() && dirsFirst ) {
194 bigger = fi2->isDir();
199 TQDir::SortSpec sort =
static_cast<TQDir::SortSpec
>(m_sorting & TQDir::SortByMask);
208 if ( (m_sorting & TQDir::IgnoreCase) == TQDir::IgnoreCase )
209 bigger = (fi1->name(
true ) > fi2->name(
true ));
211 bigger = (fi1->name() > fi2->name());
215 time_t t1 = fi1->time( TDEIO::UDS_MODIFICATION_TIME );
216 time_t t2 = fi2->time( TDEIO::UDS_MODIFICATION_TIME );
231 TDEIO::filesize_t s1 = fi1->size();
232 TDEIO::filesize_t s2 = fi2->size();
245 case TQDir::Unsorted:
252 if (reversed && !keepFirst )
255 return (bigger ? 1 : -1);
270 if (!filename.isNull()) {
272 for ( (item = firstFileItem()); item; item = nextItem( item ) ) {
273 if (item->name() == filename) {
280 kdDebug(tdefile_area) <<
"setCurrentItem: no match found: " << filename << endl;
285 KFileItem *item = 0L;
289 for ( (item = firstFileItem()); item; item = nextItem( item ) )
290 m_itemList.append( item );
298 if ( !m_selectedList )
299 m_selectedList =
new KFileItemList;
301 m_selectedList->clear();
304 for ( (item = firstFileItem()); item; item = nextItem( item ) ) {
306 m_selectedList->append( item );
309 return m_selectedList;
314 if (selection_mode == KFile::NoSelection || selection_mode== KFile::Single)
317 KFileItem *item = 0L;
318 for ( (item = firstFileItem()); item; item = nextItem( item ) )
325 KFileItem *item = 0L;
326 for ( (item = firstFileItem()); item; item = nextItem( item ) )
331 void KFileView::setSelectionMode( KFile::SelectionMode sm )
336 KFile::SelectionMode KFileView::selectionMode()
const
338 return selection_mode;
341 void KFileView::setViewMode( ViewMode vm )
356 if ( m_selectedList )
357 m_selectedList->removeRef( item );
368 d->actions =
new TDEActionCollection(
widget(),
"KFileView::d->actions" );
372 void KFileView::readConfig( TDEConfig *,
const TQString& )
376 void KFileView::writeConfig( TDEConfig *,
const TQString& )
382 bool reverse = sortSpec & TQDir::Reversed;
383 bool dirsFirst = sortSpec & TQDir::DirsFirst;
384 char start = (isDir && dirsFirst) ? (reverse ?
'2' :
'0') :
'1';
385 TQString result = (sortSpec & TQDir::IgnoreCase) ? value.lower() : value;
386 return result.prepend( start );
391 bool reverse = sortSpec & TQDir::Reversed;
392 bool dirsFirst = sortSpec & TQDir::DirsFirst;
393 char start = (isDir && dirsFirst) ? (reverse ?
'2' :
'0') :
'1';
394 return TDEIO::number( value ).rightJustify( 24,
'0' ).prepend( start );
399 virtual_hook(VIRTUAL_SET_DROP_OPTIONS, &options);
402 void KFileView::setDropOptions_impl(
int options)
404 d->dropOptions = options;
409 return d->dropOptions;
412 int KFileView::autoOpenDelay()
414 return (TQApplication::startDragTime() * 3) / 2;
417 void KFileView::virtual_hook(
int id,
void* data)
420 case VIRTUAL_SET_DROP_OPTIONS:
421 setDropOptions_impl(*(
int *)data);
429 #include "tdefileview.moc"
void setCurrentItem(const TQString &filename)
Sets filename the current item in the view, if available.
void setDropOptions(int options)
Specify DND options.
const KFileItemList * items() const
virtual TDEActionCollection * actionCollection() const
virtual void insertItem(KFileItem *i)
The derived view must implement this function to add the file in the widget.
This class defines an interface to all file views.
virtual void clear()
Clears the view and all item lists.
TQDir::SortSpec sorting() const
Returns the sorting order of the internal list.
const KFileItemList * selectedItems() const
virtual void selectAll()
Selects all items.
virtual void setSelected(const KFileItem *, bool enable)=0
Tells the view that it should highlight the item.
int dropOptions()
Returns the DND options in effect.
virtual TQWidget * widget()=0
a pure virtual function to get a TQWidget, that can be added to other widgets.
void addItemList(const KFileItemList &list)
inserts a list of items.
virtual ~KFileView()
Destructor.
virtual bool isSelected(const KFileItem *) const =0
virtual void removeItem(const KFileItem *item)
Removes an item from the list; has to be implemented by the view.
virtual void invertSelection()
Inverts the current selection, i.e.
virtual void setSorting(TQDir::SortSpec sort)
Sets the sorting order of the view.
virtual void updateView(bool f=true)
does a repaint of the view.
internal class to make easier to use signals possible
virtual void clearView()=0
pure virtual function, that should be implemented to clear the view.
static TQString sortingKey(const TQString &value, bool isDir, int sortSpec)
This method calculates a TQString from the given parameters, that is suitable for sorting with e...
bool updateNumbers(const KFileItem *i)
increases the number of dirs and files.
virtual void listingCompleted()
This hook is called when all items of the currently listed directory are listed and inserted into the...