22 #include <tqkeycode.h>
24 #include <tqpainter.h>
27 #include <tdeapplication.h>
28 #include <tdefileitem.h>
29 #include <tdeglobal.h>
30 #include <tdeglobalsettings.h>
31 #include <kiconloader.h>
32 #include <kicontheme.h>
33 #include <tdelocale.h>
37 #include "tdefiledetailview.h"
38 #include "config-tdefile.h"
47 class KFileDetailView::KFileDetailViewPrivate
50 KFileDetailViewPrivate() : dropItem(0)
54 TQTimer autoOpenTimer;
57 KFileDetailView::KFileDetailView(TQWidget *parent,
const char *name)
58 : TDEListView(parent, name),
KFileView(), d(new KFileDetailViewPrivate())
61 m_sortingCol = COL_NAME;
62 m_blockSortingSignal =
false;
63 setViewName( i18n(
"Detailed View") );
65 addColumn( i18n(
"Name" ) );
66 addColumn( i18n(
"Size" ) );
67 addColumn( i18n(
"Date" ) );
68 addColumn( i18n(
"Permissions" ) );
69 addColumn( i18n(
"Owner" ) );
70 addColumn( i18n(
"Group" ) );
71 setShowSortIndicator(
true );
72 setAllColumnsShowFocus(
true );
75 connect( header(), TQ_SIGNAL( clicked(
int)),
76 TQ_SLOT(slotSortingChanged(
int) ));
79 connect(
this, TQ_SIGNAL( returnPressed(TQListViewItem *) ),
80 TQ_SLOT( slotActivate( TQListViewItem *) ) );
82 connect(
this, TQ_SIGNAL( clicked(TQListViewItem *,
const TQPoint&,
int)),
83 TQ_SLOT( selected( TQListViewItem *) ) );
84 connect(
this, TQ_SIGNAL( doubleClicked(TQListViewItem *,
const TQPoint&,
int)),
85 TQ_SLOT( slotActivate( TQListViewItem *) ) );
87 connect(
this, TQ_SIGNAL(contextMenuRequested( TQListViewItem *,
88 const TQPoint &,
int )),
89 this, TQ_SLOT( slotActivateMenu( TQListViewItem *,
const TQPoint& )));
91 KFile::SelectionMode sm = KFileView::selectionMode();
94 TQListView::setSelectionMode( TQListView::Multi );
97 TQListView::setSelectionMode( TQListView::Extended );
99 case KFile::NoSelection:
100 TQListView::setSelectionMode( TQListView::NoSelection );
104 TQListView::setSelectionMode( TQListView::Single );
109 if ( sm == KFile::Multi || sm == KFile::Extended )
110 connect(
this, TQ_SIGNAL( selectionChanged() ),
111 TQ_SLOT( slotSelectionChanged() ));
113 connect(
this, TQ_SIGNAL( selectionChanged( TQListViewItem * ) ),
114 TQ_SLOT( highlighted( TQListViewItem * ) ));
117 connect( &(d->autoOpenTimer), TQ_SIGNAL( timeout() ),
118 this, TQ_SLOT( slotAutoOpen() ));
120 setSorting( sorting() );
123 new KMimeTypeResolver<KFileListViewItem,KFileDetailView>(
this );
126 KFileDetailView::~KFileDetailView()
132 void KFileDetailView::readConfig( TDEConfig *config,
const TQString& group )
134 restoreLayout( config, group );
137 void KFileDetailView::writeConfig( TDEConfig *config,
const TQString& group )
139 saveLayout( config, group );
151 TDEListView::setSelected( item, enable );
160 TDEListView::setCurrentItem( it );
174 TDEListView::clearSelection();
179 if (KFileView::selectionMode() == KFile::NoSelection ||
180 KFileView::selectionMode() == KFile::Single)
183 TDEListView::selectAll(
true );
188 TDEListView::invertSelection();
191 void KFileDetailView::slotActivateMenu (TQListViewItem *item,
const TQPoint& pos )
194 sig->activateMenu( 0, pos );
198 sig->activateMenu( i->
fileInfo(), pos );
203 m_resolver->m_lstPendingMimeIconItems.clear();
204 TDEListView::clear();
213 setSortingKey( item, i );
215 i->setExtraData(
this, item );
217 if ( !i->isMimeTypeKnown() )
218 m_resolver->m_lstPendingMimeIconItems.append( item );
221 void KFileDetailView::slotActivate( TQListViewItem *item )
231 void KFileDetailView::selected( TQListViewItem *item )
236 if ( TDEGlobalSettings::singleClick() ) {
243 void KFileDetailView::highlighted( TQListViewItem *item )
254 void KFileDetailView::setSelectionMode( KFile::SelectionMode sm )
256 disconnect(
this, TQ_SIGNAL( selectionChanged() ));
257 disconnect(
this, TQ_SIGNAL( selectionChanged( TQListViewItem * ) ));
259 KFileView::setSelectionMode( sm );
261 switch ( KFileView::selectionMode() ) {
263 TQListView::setSelectionMode( TQListView::Multi );
265 case KFile::Extended:
266 TQListView::setSelectionMode( TQListView::Extended );
268 case KFile::NoSelection:
269 TQListView::setSelectionMode( TQListView::NoSelection );
273 TQListView::setSelectionMode( TQListView::Single );
277 if ( sm == KFile::Multi || sm == KFile::Extended )
278 connect(
this, TQ_SIGNAL( selectionChanged() ),
279 TQ_SLOT( slotSelectionChanged() ));
281 connect(
this, TQ_SIGNAL( selectionChanged( TQListViewItem * )),
282 TQ_SLOT( highlighted( TQListViewItem * )));
291 return (item && item->isSelected());
300 TQListViewItemIterator it( (TQListView*)
this );
301 for ( ; it.current(); ++it ) {
303 item->setPixmap( 0, item->
fileInfo()->pixmap(TDEIcon::SizeSmall) );
317 setSortingKey( item, i );
328 if ( spec & TQDir::Time )
329 item->setKey(
sortingKey( i->time( TDEIO::UDS_MODIFICATION_TIME ),
331 else if ( spec & TQDir::Size )
332 item->setKey(
sortingKey( i->size(), i->isDir(), spec ));
335 item->setKey(
sortingKey( i->text(), i->isDir(), spec ));
345 m_resolver->m_lstPendingMimeIconItems.remove( item );
351 void KFileDetailView::slotSortingChanged(
int col )
355 TQDir::SortSpec sort =
sorting();
357 bool reversed = (col == m_sortingCol) && (sort & TQDir::Reversed) == 0;
362 sortSpec = ((sort & ~TQDir::SortByMask) | TQDir::Name);
365 sortSpec = ((sort & ~TQDir::SortByMask) | TQDir::Size);
368 sortSpec = ((sort & ~TQDir::SortByMask) | TQDir::Time);
377 sortSpec = (sort & ~TQDir::SortByMask);
384 sortSpec |= TQDir::Reversed;
386 sortSpec &= ~TQDir::Reversed;
388 if ( sort & TQDir::IgnoreCase )
389 sortSpec |= TQDir::IgnoreCase;
391 sortSpec &= ~TQDir::IgnoreCase;
397 KFileItemListIterator it( *
items() );
399 if ( sortSpec & TQDir::Time ) {
400 for ( ; (item = it.current()); ++it )
401 viewItem(item)->setKey(
sortingKey( item->time( TDEIO::UDS_MODIFICATION_TIME ), item->isDir(), sortSpec ));
404 else if ( sortSpec & TQDir::Size ) {
405 for ( ; (item = it.current()); ++it )
406 viewItem(item)->setKey(
sortingKey( item->size(), item->isDir(),
410 for ( ; (item = it.current()); ++it ) {
412 i->setKey(
sortingKey( i->text(m_sortingCol), item->isDir(),
417 TDEListView::setSorting( m_sortingCol, !reversed );
420 if ( !m_blockSortingSignal )
421 sig->changeSorting(
static_cast<TQDir::SortSpec
>( sortSpec ) );
428 if ( spec & TQDir::Time )
430 else if ( spec & TQDir::Size )
432 else if ( spec & TQDir::Unsorted )
438 if ( spec & TQDir::Reversed )
439 spec = (TQDir::SortSpec) (spec & ~TQDir::Reversed);
441 spec = (TQDir::SortSpec) (spec | TQDir::Reversed);
448 m_blockSortingSignal =
true;
449 slotSortingChanged( col );
450 m_blockSortingSignal =
false;
461 TDEListView::ensureItemVisible( item );
465 void KFileDetailView::slotSelectionChanged()
470 KFileItem * KFileDetailView::firstFileItem()
const
478 KFileItem * KFileDetailView::nextItem(
const KFileItem *fileItem )
const
482 if ( item && item->itemBelow() )
488 return firstFileItem();
491 KFileItem * KFileDetailView::prevItem(
const KFileItem *fileItem )
const
495 if ( item && item->itemAbove() )
501 return firstFileItem();
504 void KFileDetailView::keyPressEvent( TQKeyEvent *e )
506 TDEListView::keyPressEvent( e );
508 if ( e->key() == Key_Return || e->key() == Key_Enter ) {
509 if ( e->state() & ControlButton )
519 void KFileDetailView::mimeTypeDeterminationFinished()
526 (void) item->
fileInfo()->determineMimeType();
535 TQDragObject *KFileDetailView::dragObject()
540 for ( ; it.current(); ++it ){
541 urls.append( (*it)->url() );
544 if( urls.count() > 1 )
545 pixmap = DesktopIcon(
"application-vnd.tde.tdemultiple", TDEIcon::SizeSmall );
546 if( pixmap.isNull() )
550 hotspot.setX( pixmap.width() / 2 );
551 hotspot.setY( pixmap.height() / 2 );
552 TQDragObject* myDragObject =
new KURLDrag( urls,
widget() );
553 myDragObject->setPixmap( pixmap, hotspot );
557 void KFileDetailView::slotAutoOpen()
559 d->autoOpenTimer.stop();
563 KFileItem *fileItem = d->dropItem->fileInfo();
567 if( fileItem->isFile() )
570 if ( fileItem->isDir() || fileItem->isLink())
574 bool KFileDetailView::acceptDrag(TQDropEvent* e)
const
576 return KURLDrag::canDecode( e ) &&
578 ( e->action() == TQDropEvent::Copy
579 || e->action() == TQDropEvent::Move
580 || e->action() == TQDropEvent::Link );
583 void KFileDetailView::contentsDragEnterEvent( TQDragEnterEvent *e )
585 if ( ! acceptDrag( e ) ) {
597 d->autoOpenTimer.start( autoOpenDelay() );
602 d->autoOpenTimer.stop();
606 void KFileDetailView::contentsDragMoveEvent( TQDragMoveEvent *e )
608 if ( ! acceptDrag( e ) ) {
619 if (d->dropItem != item)
622 d->autoOpenTimer.start( autoOpenDelay() );
628 d->autoOpenTimer.stop();
632 void KFileDetailView::contentsDragLeaveEvent( TQDragLeaveEvent * )
635 d->autoOpenTimer.stop();
638 void KFileDetailView::contentsDropEvent( TQDropEvent *e )
641 d->autoOpenTimer.stop();
643 if ( ! acceptDrag( e ) ) {
650 KFileItem * fileItem = 0;
657 if (KURLDrag::decode( e, urls ) && !urls.isEmpty())
659 emit
dropped(e, urls, fileItem ? fileItem->url() : KURL());
660 sig->dropURLs(fileItem, e, urls);
670 KFileListViewItem::setPixmap( COL_NAME, inf->pixmap(TDEIcon::SizeSmall));
672 setText( COL_NAME, inf->text() );
673 setText( COL_SIZE, TDEGlobal::locale()->formatNumber( inf->size(), 0));
674 setText( COL_DATE, inf->timeString() );
675 setText( COL_PERM, inf->permissionsString() );
676 setText( COL_OWNER, inf->user() );
677 setText( COL_GROUP, inf->group() );
681 void KFileDetailView::virtual_hook(
int id,
void* data )
682 { TDEListView::virtual_hook(
id, data );
683 KFileView::virtual_hook(
id, data ); }
685 #include "tdefiledetailview.moc"
A list-view capable of showing KFileItem'.
virtual void setCurrentItem(const KFileItem *)
Reimplement this to set item the current item in the view, e.g.
virtual bool isSelected(const KFileItem *i) const
virtual void selectAll()
Selects all items.
virtual void insertItem(KFileItem *i)
The derived view must implement this function to add the file in the widget.
void ensureItemVisible(const KFileItem *)
pure virtual function, that should be implemented to make item i visible, i.e.
virtual void listingCompleted()
This hook is called when all items of the currently listed directory are listed and inserted into the...
virtual void setSelected(const KFileItem *, bool)
Tells the view that it should highlight the item.
virtual TQWidget * widget()
a pure virtual function to get a TQWidget, that can be added to other widgets.
virtual void clearView()
pure virtual function, that should be implemented to clear the view.
virtual void invertSelection()
Inverts the current selection, i.e.
virtual void clearSelection()
Clears any selection, unhighlights everything.
virtual void updateView(bool)
does a repaint of the view.
virtual void setSorting(TQDir::SortSpec)
Sets the sorting order of the view.
virtual void removeItem(const KFileItem *)
Removes an item from the list; has to be implemented by the view.
virtual KFileItem * currentFileItem() const
void dropped(TQDropEvent *event, KFileItem *fileItem)
The user dropped something.
An item for the listiew, that has a reference to its corresponding KFileItem.
KFileItem * fileInfo() const
void activate(const KFileItem *item)
Call this method when an item is selected (depends on single click / double click configuration).
void highlightFile(const KFileItem *i)
emits the highlighted signal for item.
This class defines an interface to all file views.
bool onlyDoubleClickSelectsFiles() const
virtual void insertItem(KFileItem *i)
The derived view must implement this function to add the file in the widget.
const KFileItemList * items() const
const KFileItemList * selectedItems() const
TQDir::SortSpec sorting() const
Returns the sorting order of the internal list.
int dropOptions()
Returns the DND options in effect.
virtual void removeItem(const KFileItem *item)
Removes an item from the list; has to be implemented by the view.
virtual void setSorting(TQDir::SortSpec sort)
Sets the sorting order of 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....