File: ViewTable.cpp

package info (click to toggle)
bsc 2.27-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,644 kB
  • ctags: 2,610
  • sloc: cpp: 14,104; perl: 114; makefile: 46
file content (1021 lines) | stat: -rw-r--r-- 34,774 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
/********************************************************************
 * Copyright (C) 2005, 2006 Piotr Pszczolkowski
 *-------------------------------------------------------------------
 * This file is part of BSCommander (Beesoft Commander).
 *
 * BsC is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * BsC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with BsC; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *******************************************************************/

/*------- include files:
-------------------------------------------------------------------*/
#include "ViewTable.h"
#include "Shared.h"
#include "ViewTableItem.h"
#include "Config.h"
#include <qapplication.h>
#include <qdragobject.h> 
#include <qinputdialog.h>
#include <qregexp.h>
#include <qpainter.h>
#include <qcolor.h>
#include <qpopupmenu.h>
#include <qradiobutton.h>
#include <qbuttongroup.h>
#include <qheader.h>
#include <qurlinfo.h>
using namespace std;

/*------- local constants:
-------------------------------------------------------------------*/
const ViewTable::ColumnDef ViewTable::COLDEF[] =
{
	{ QT_TR_NOOP("Name")  , Qt::AlignLeft    },
	{ QT_TR_NOOP("Ext")   , Qt::AlignLeft    },
	{ QT_TR_NOOP("Access"), Qt::AlignHCenter },
	{ QT_TR_NOOP("Size")  , Qt::AlignRight    },
	{ QT_TR_NOOP("Date")  , Qt::AlignHCenter  },
	{ QT_TR_NOOP("Time")  , Qt::AlignHCenter  },
	{ QT_TR_NOOP("Owner") , Qt::AlignHCenter  },
	{ QT_TR_NOOP("Group") , Qt::AlignHCenter  }
};
//...................................................................
const QString ViewTable::FOLDER_ICON              = "folder.png";
const QString ViewTable::IFOLDER_ICON             = "ifolder.png";
const QString ViewTable::DRAG_DROP_ICON           = "drag.png";
const QString ViewTable::DRAG_DROP_SUBTYPE        = "text/copy";
const QString ViewTable::DRAG_DROP_CMD            = "copy or move";
const QColor  ViewTable::CTXMENU_BACKGROUND_COLOR = qRgb( 0xdd, 0xdd, 0xdd );
//...................................................................
const QString ViewTable::FILE_SELECTION_CAPTION   = QT_TR_NOOP( "File selection" );
const QString ViewTable::FILE_SELECTION_PROMPT    = QT_TR_NOOP( "Enter selection mask" );
const QString ViewTable::FILE_DESELECTION_CAPTION = QT_TR_NOOP( "File deselection" );
const QString ViewTable::FILE_DESELECTION_PROMPT  = QT_TR_NOOP( "Enter deselection mask" );

//*******************************************************************
// ViewTable
//*******************************************************************
ViewTable::ViewTable( QWidget* const in_parent )
: QListView( in_parent )
, d_timer( this )
, d_sel_counter( 0 )
, d_fname_on_start( Shared::EmptyStr )
, d_selection_mode(( Config::NC == Config::instance()->selection_mode()) ? Multi : Extended )
{
	viewport()->setAcceptDrops( TRUE );
	setAcceptDrops( TRUE );
	setShowSortIndicator( TRUE );
	setSelectionMode( d_selection_mode );
	setAllColumnsShowFocus( TRUE );

	for( int i = 0; i < COLUMNS; ++i ) {
		addColumn( tr(COLDEF[i].name) );
		setColumnAlignment ( i, COLDEF[i].align );
	}
	
	connect( this     , SIGNAL( selectionChanged() ),
				this     , SLOT  ( selection_changed() ));
	connect( this     , SIGNAL( rightButtonClicked( QListViewItem*, const QPoint&, int )),
				this     , SLOT  ( context_menu( QListViewItem*, const QPoint&, int )));
	connect( this     , SIGNAL( F2() ),
				in_parent, SLOT  ( F2() ));
	connect( this     , SIGNAL( F3() ),
				in_parent, SLOT  ( F3() ));
	connect( this     , SIGNAL( F4() ),
				in_parent, SLOT  ( F4() ));
	connect( this     , SIGNAL( F5() ),
				in_parent, SIGNAL( F5() ));
	connect( this     , SIGNAL( F6() ),
				in_parent, SLOT  ( F6() ));
	connect( this     , SIGNAL( F8() ),
				in_parent, SLOT  ( F8() ));
	connect( this     , SIGNAL( F9() ),
				in_parent, SIGNAL( F9() ));
	connect( this     , SIGNAL( empty() ),
				in_parent, SLOT  ( empty() ));
	connect( this     , SIGNAL( touch() ),
				in_parent, SLOT  ( touch() ));
	connect( this     , SIGNAL( disp_dir_size( ViewTableItem* ) ),
	         in_parent, SLOT  ( disp_dir_size( ViewTableItem* ) ));
	connect( &d_timer , SIGNAL( timeout()),
	         this     , SLOT  ( timeout()) );
}
// end of ViewTable

//*******************************************************************
// keyPressEvent                                   PRIVATE inherited
//*******************************************************************
void ViewTable::keyPressEvent( QKeyEvent* e )
{
	bool accepted = FALSE;
	
	if( Qt::ControlButton == e->state() ) {
		switch( e->key() ) {
			case Qt::Key_Home:
				e->accept();
				accepted = TRUE;
				emit cd_home();
				break;
			case Qt::Key_Prior:
				e->accept();
				accepted = TRUE;
				emit cd_up();
				break;
			case Qt::Key_N:
				e->accept();
				accepted = TRUE;
				emit touch();
				break;
			case Qt::Key_E:
				e->accept();
				accepted = TRUE;
				emit empty();
				break;
			case Qt::Key_Backspace:
				e->accept();
				accepted = TRUE;
				emit cd_root();
				break;
		}
	}
	else if( Qt::AltButton == e->state() ) {
		switch( e->key() ) {
			case Qt::Key_Space:
				ViewTableItem* const item = dynamic_cast<ViewTableItem*>( currentItem() );
				if( item ) {
					if( item->is_dir() && item->is_readable() ) {
						emit disp_dir_size( item );
					}
				}
				break;
		}
	}
	else {
		switch( e->key() ) {
			case Qt::Key_Backspace:
				e->accept();
				accepted = TRUE;
				emit cd_up();
				break;
			case Qt::Key_Delete:
				e->accept();
				accepted = TRUE;
				emit remove();
				break;
			case Qt::Key_Plus:
				e->accept();
				accepted = TRUE;
				select_plus();
				break;
			case Qt::Key_Minus:
				e->accept();
				accepted = TRUE;
				select_minus();
				break;
			case Qt::Key_Asterisk:
				e->accept();
				accepted = TRUE;
				invertSelection();
				break;
			case Qt::Key_F2:
				e->accept();
				accepted = TRUE;
				emit F2();
				break;
			case Qt::Key_Insert:
				if( Multi == d_selection_mode ) {
					e->accept();
					accepted = TRUE;
					select_this_one();
				}
				break;
			case Qt::Key_Space:
				if( Multi == d_selection_mode ) {
					e->accept();
					accepted = TRUE;
					// nic nie rob
				}
				break;
			
		}
	}
	
	if( FALSE == accepted ) {
		QListView::keyPressEvent( e );
	}
}
// end of keyPressEvent
/*
void ViewTable::contentsMousePressEvent ( QMouseEvent * e )
{
	qWarning( "ViewTable::QMouseEvent" );
	QListView::contentsMousePressEvent ( QMouseEvent * e );
}
*/
//*******************************************************************
// select_this_one                                           PRIVATE
//*******************************************************************
void ViewTable::select_this_one()
{
	ViewTableItem* const item = dynamic_cast<ViewTableItem*>( currentItem() );
	if( item ) {
		const bool new_state = ( FALSE == isSelected( item ) );
		setSelected( item, new_state );
		
		QListViewItem* const next_item = item->itemBelow();
		setCurrentItem( next_item );
		ensureItemVisible( next_item );
	}
}
// end of select_this_one

//*******************************************************************
// select_item_after_start                                    PUBLIC
//*******************************************************************
void ViewTable::select_item_after_start()
{
	if( FALSE == d_fname_on_start.isEmpty() ) {
		select_by_name( d_fname_on_start );
		d_fname_on_start = Shared::EmptyStr;
	}
}
// end of select_item_after_start

//*******************************************************************
// showEvent                                       PRIVATE inherited
//*******************************************************************
void ViewTable::showEvent( QShowEvent* e )
{
	QListView::showEvent( e );
	select_item_after_start();
	adjust();
}
// end of showEvent

//*******************************************************************
// setSorting                                      PRIVATE inherited
//*******************************************************************
void ViewTable::setSorting( int in_column, bool in_ascending )
{
	QListView::setSorting( in_column, in_ascending );
	ensureItemVisible( currentItem() );
}
// end of setSorting

//*******************************************************************
// adjust                                                     PUBLIC
//*******************************************************************
void ViewTable::adjust()
{
	static bool first_time = TRUE;
	bool adjust = TRUE;
	
	if( 1 == Config::instance()->disable_columns_resize()	) {
		if( first_time ) first_time = FALSE;
		else             adjust = FALSE;
	}

	if( adjust ) {
		for( int col = COL_FNAME; col < COLUMNS; ++col ) {
			adjustColumn( col );
		}
	}
}
// end of adjust

//*******************************************************************
// reset                                                      PUBLIC
//*******************************************************************
void ViewTable::reset()
{
	QListViewItem* item = firstChild();
	while ( item ) {
		takeItem( item );
		item = firstChild();
   }
}
// end of add_new_item

//*******************************************************************
// add_new_item                                               PUBLIC
//*******************************************************************
// wersja nr. 1 dla lokalnego systemu plikow
//-------------------------------------------
void ViewTable::add_new_item( const QFileInfo& in_fi, const bool in_is_root )
{
	if( can_display( in_fi.fileName(), in_is_root )) {
		display_item_info( in_fi );
	}
}
// wersja nr. 2 dla ftp
//---------------------
void ViewTable::add_new_item( const QUrlInfo& in_ui, const bool in_is_root )
{
	if( can_display( in_ui.name(), in_is_root )) {
		display_item_info( in_ui );
	}
}
// end of add_new_item

//*******************************************************************
// get_fname_fext                                             PUBLIC
//*******************************************************************
void ViewTable::get_fname_fext( const ViewTableItem* const in_item, QString& out_fname, QString& out_fext )
{
	out_fname = in_item->text( COL_FNAME );
	out_fext  = in_item->text( COL_FEXT );
}
// end of get_current_name

//*******************************************************************
// get_fname                                                  PUBLIC
//*******************************************************************
void ViewTable::get_fname( const ViewTableItem* const in_item, QString& out_fname )
{
	QString fext;
	get_fname_fext( in_item, out_fname, fext );
	if( !fext.isEmpty() ) {
		out_fname += Shared::Point;
		out_fname += fext;
	}
}
// end of get_fname

//*******************************************************************
// get_current_fname_fext                                     PUBLIC
//*******************************************************************
void ViewTable::get_current_fname_fext( QString& out_fname, QString& out_fext )
{
	out_fname = Shared::EmptyStr;
	const ViewTableItem* const item = dynamic_cast<ViewTableItem*>( currentItem() );
	if( item ){
		get_fname_fext( item, out_fname, out_fext );
	}
}
// end of get_current_fname_fext

//*******************************************************************
// get_current_info                                          PUBLIC
//*******************************************************************
bool ViewTable::get_current_info( QString& out_fname, bool& out_isdir )
{
	bool retval = FALSE;
	const ViewTableItem* const item = current_item();
	if( item ) {
		get_fname( item, out_fname );
		out_isdir = item->is_dir();
		retval = TRUE;
	}
	return retval;
}
// end of get_current_info

//*******************************************************************
// get_current_fname                                          PUBLIC
//*******************************************************************
void ViewTable::get_current_fname( QString& out_fname )
{
	out_fname = Shared::EmptyStr;
	const ViewTableItem* const item = current_item();
	if( item ){
		get_fname( item, out_fname );
	}
}
// end of get_current_fname

//*******************************************************************
// check_parent_mark                                          PUBLIC
//-------------------------------------------------------------------
// To jest funkcja reagujaca na rozne dzialanie serwerow ftp.
// Niektore przy odczycie katalogu zwracaja "..", a inne nie.
// My znak katalogu ".." potrzebujemy.
// Ta funkcja ma sprawdzic, czy jest on czy nie. Jesli go nie,
// ma go dodac.
//*******************************************************************
void ViewTable::check_parent_mark()
{
	if( 0 == findItem( Shared::ParentDir, COL_FNAME ) ) {
		QUrlInfo ui;
		ui.setName( Shared::ParentDir );
		ui.setDir( TRUE );
		display_item_info( ui );
	}
}
// end of check_parent_mark

//*******************************************************************
// set_dir_size                                               PUBLIC
//*******************************************************************
void ViewTable::set_dir_size( ViewTableItem* const in_item, const Q_ULLONG in_value )
{
	in_item->set_is_size_computed();
	in_item->setText( COL_SIZE, Shared::num2str( in_value ));
	adjust();
}
// end of set_dir_size


//###################################################################
//#                                                                 #
//#              OPERACJE ZWIAZANE Z ZAZNACZANIEM                   #
//#                                                                 #
//###################################################################


//*******************************************************************
// select_by_name                                             PUBLIC
//*******************************************************************
void ViewTable::select_by_name( const QString& in_fname, const QString& in_fext )
{
	bool found = FALSE;
	
	QListViewItemIterator it( this );
	while ( it.current() ) {
    	if( in_fname == (*it)->text( COL_FNAME ) ) {
			if( in_fext == (*it)->text( COL_FEXT ) ) {
//				setSelected( *it, TRUE );
				setCurrentItem( *it );
				ensureItemVisible( *it );
				found = TRUE;
				break;
			}
		}
		++it;
   }
   
	if( FALSE == found ) {
		select_first_item();
	}
}
void ViewTable::select_by_name( const QString& in_fname )
{
	const QFileInfo fi( in_fname );
	const QString fname = fi.baseName( TRUE );
	const QString fext = fi.extension( FALSE );
	select_by_name( fname, fext );
}
// end of select_by_name

void ViewTable::select_first_item()
{
	QListViewItem* const item = firstChild();
	if( item ) {
		setCurrentItem( item );
		ensureItemVisible( item );
	}
}

//*********************************************************
// select_dir_by_name                               PUBLIC
//*********************************************************
void ViewTable::select_dir_by_name( const QString& in_dname )
{
	QListViewItemIterator it( this );
	while ( it.current() ) {
    	if( in_dname == (*it)->text( COL_FNAME ) ) {
//			setSelected( *it, TRUE );
			setCurrentItem( *it );
			ensureItemVisible( *it );
			break;
		}
		++it;
   }
}
// end of select_dir_by_name

//*******************************************************************
// select_plus                                               PRIVATE
//-------------------------------------------------------------------
// Uzytkownik wcisnal klawisz '+'.
// Oznacza to, ze chce dokonac zaznaczenia plikow.
// W tym celu musi oczywiscie podac maske wyszukiwania.
//*******************************************************************
void ViewTable::select_plus()
{
	if( childCount() > 0 ) {
		bool ok = TRUE;
		const QString mask = QInputDialog::getText(
										tr(FILE_SELECTION_CAPTION), tr(FILE_SELECTION_PROMPT),
										QLineEdit::Normal, QString::null,
										&ok, this );
		if( TRUE == ok ) {										
			QString fname = Shared::EmptyStr;
			QRegExp regexp( mask, TRUE, TRUE );

   		QListViewItemIterator it( this );
    		while ( it.current() ) {
    			ViewTableItem* const item = dynamic_cast<ViewTableItem*>( *it );
    			get_fname( item, fname );
    			if( fname != Shared::ParentDir ) {
    				if( !item->isSelected() ) {
    					if( regexp.search( fname, 0 ) != -1 ) {
    						setSelected( item, TRUE );
    					}
    				}
    			}
  	      	++it;
   	 	}
		}
	}
}
// end of select_plus

//*******************************************************************
// select_minus                                              PRIVATE
//-------------------------------------------------------------------
// Uzytkownik wcisnal klawisz '-'.
// Oznacza to, ze chce dokonac zniesienia zaznaczen.
// W tym celu musi oczywiscie podac maske wyszukiwania.
//*******************************************************************
void ViewTable::select_minus()
{
	if( childCount() > 0 ) {
		bool ok = TRUE;
		const QString mask = QInputDialog::getText(
										tr(FILE_DESELECTION_CAPTION), tr(FILE_DESELECTION_PROMPT),
										QLineEdit::Normal, QString::null,
										&ok, this );
		if( TRUE == ok ) {										
			QString fname = "";
			QRegExp regexp( mask, TRUE, TRUE );

   		QListViewItemIterator it( this );
    		while ( it.current() ) {
    			ViewTableItem* const item = dynamic_cast<ViewTableItem*>( *it );
    			get_fname( item, fname );
    			if( fname != Shared::ParentDir ) {
    				if( item->isSelected() ) {
    					if( regexp.search( fname, 0 ) != -1 ) {
    						setSelected( item, FALSE );
    					}
    				}
    			}
  	      	++it;
   	 	}
		}
	}
}
// end of select_minus

//*******************************************************************
// selections                                                 PUBLIC
//-------------------------------------------------------------------
// Pierwszenstwo we wszelkich operacjach maja pozycje zaznaczone.
// Jesli takich nie ma przedmiotem operacji bedzie pozycja aktualna.
//*******************************************************************
const ViewTable::SelectedItems& ViewTable::selections()
{
	d_selections.clear();

	QListViewItemIterator it( this );
	while ( it.current() ) {
   	if( (*it)->isSelected() ) {
   		ViewTableItem* const item = dynamic_cast<ViewTableItem*>( *it );
   		if( FALSE == item->is_parent_dir() ) {
    			d_selections.push_back( item );
   		}
		}
		++it;
   }
	
	if( d_selections.empty() ) {
		ViewTableItem* const item = dynamic_cast<ViewTableItem*>( currentItem() );
		if( FALSE == item->is_parent_dir() ) {
    		d_selections.push_back( item );
   	}
	}

	return d_selections;
}
// end of selections

//*******************************************************************
// set_fname_on_start                                         PUBLIC
//*******************************************************************
void ViewTable::set_fname_on_start( const QString& in_fname )
{
	d_fname_on_start = in_fname;
}
// end of set_fname_on_start

//*******************************************************************
// get_selections_number                                     PRIVATE
//*******************************************************************
int ViewTable::get_selections_number()
{
	int counter = 0;
	
	if( childCount() > 0 ) {
   	QListViewItemIterator it( this );
    	while ( it.current() ) {
  			if( (*it)->isSelected() ) ++counter;
  	     	++it;
  		}
	}
	return counter;
}
// end of get_selections_number

//###################################################################
//#                                                                 #
//#            OBSLUGA ZDARZEN ZWIAZANYCH Z FOCUSEM                 #
//#                                                                 #
//###################################################################


//*******************************************************************
// focusInEvent                                    PRIVATE inherited
//-------------------------------------------------------------------
// Zmiana wygladu po otrzymaniu focusa.
//*******************************************************************
void ViewTable::focusInEvent( QFocusEvent* in_event )
{
	QListView::focusInEvent( in_event );
	updateContents();
	ensureItemVisible( currentItem() );
}
// end of focusInEvent

//*******************************************************************
// focusOutEvent                                   PRIVATE inherited
//-------------------------------------------------------------------
// Zmiana wygladu po utracie focusa.
//*******************************************************************
void ViewTable::focusOutEvent ( QFocusEvent* in_event )
{
	QListView::focusOutEvent( in_event );
	updateContents();
	
	const ViewTableItem* const item = current_item();
	d_fname_on_start = ( item ) ? item->name() : Shared::EmptyStr;
}
// end of focusOutEvent


//*******************************************************************
// viewportMousePressEvent                         PRIVATE inherited
//*******************************************************************
void ViewTable::viewportMousePressEvent( QMouseEvent* const in_event )
{
	if( Multi == d_selection_mode ) {
		QListViewItem* const item = itemAt( in_event->pos() );
		if( item ) {
			if( Qt::LeftButton == in_event->button() ) {
				setCurrentItem( item );
			}
			else if( Qt::RightButton == in_event->button() ) {
				setCurrentItem( item );
				setSelected( item, FALSE == item->isSelected() );
			}
			else {
				QListView::viewportMousePressEvent( in_event );
			}
		}
	}
	else {
		QListView::viewportMousePressEvent( in_event );
	}
}
// end of viewportMousePressEvent


//###################################################################
//#                                                                 #
//#                        DRAG & DROP                              #
//#                                                                 #
//###################################################################


//*******************************************************************
// contentsMousePressEvent                         PRIVATE inherited
//*******************************************************************
void ViewTable::contentsMousePressEvent( QMouseEvent* in_event )
{
	if( Extended == d_selection_mode ) {
		if( LeftButton == in_event->button() ) {
			d_drag_pos = in_event->pos();
		}
	}
	QListView::contentsMousePressEvent( in_event );
}
// end of contentsMousePressEvent

//*******************************************************************
// contentsMouseMoveEvent                          PRIVATE inherited
//*******************************************************************
void ViewTable::contentsMouseMoveEvent( QMouseEvent* in_event )
{
	if( Extended == d_selection_mode ) {
		if( in_event->state() & LeftButton ) {
			const int dx = ( in_event->pos() - d_drag_pos ).manhattanLength();
			if( dx > QApplication::startDragDistance() ) {
				start_drag();
			}
		}
	}
	QListView::contentsMouseMoveEvent( in_event );
}
// end of contentsMouseMoveEvent

//*******************************************************************
// contentsDragEnterEvent                          PRIVATE inherited
//*******************************************************************
void ViewTable::contentsDragEnterEvent( QDragEnterEvent* in_event )
{
	if( Extended == d_selection_mode ) {
		in_event->accept( in_event->provides( DRAG_DROP_SUBTYPE ));
	}
}
// end of contentsDragEnterEvent

//*******************************************************************
// contentsDropEvent                               PRIVATE inherited
//*******************************************************************
void ViewTable::contentsDropEvent( QDropEvent* in_event )
{
	if( Extended == d_selection_mode ) {
		QString fname;
		if( QTextDrag::decode( in_event, fname )) {
			const QWidget* const from_widget = in_event->source();
			if( from_widget ) {
				if( from_widget != this ) {
					if( from_widget->inherits( "ViewTable" )) {
						d_timer.start( 5, TRUE );
					}
				}
			}
		}
	}
}
// end of contentsDropEvent

//*******************************************************************
// start_drag                                                PRIVATE
//*******************************************************************
void ViewTable::start_drag()
{
	if( Extended == d_selection_mode ) {
		QTextDrag* const drag_item = new QTextDrag( DRAG_DROP_CMD, this );
		drag_item->setSubtype( DRAG_DROP_SUBTYPE.utf8() );
		drag_item->setPixmap( QPixmap::fromMimeSource( DRAG_DROP_ICON ));
		drag_item->drag();
	}
}
// end of start_drag

//*******************************************************************
// timeout                                              PRIVATE slot
//*******************************************************************
void ViewTable::timeout()
{
	select_item_after_start();
	emit F5();
}
// end of timeout

//###################################################################
//#                                                                 #
//#               WYSWIETLENIE DANYCH W TABLICY                     #
//#                                                                 #
//###################################################################


//*******************************************************************
// display_item_info                                         PRIVATE
//*******************************************************************
// wersja nr. 1 dla lokalnego systemu plikow.
//-------------------------------------------
void ViewTable::display_item_info( const QFileInfo& in_fi )
{
	d_item_as_text.clear();
	
	if( Shared::ParentDir == in_fi.fileName() ) {
		d_item_as_text.info[ COL_FNAME ] = Shared::ParentDir;
	}
	else {
		get_access( in_fi, d_item_as_text.info[ COL_ACCESS ] );
		if( 'd' == d_item_as_text.info[COL_ACCESS][0] ) d_item_as_text.info[ COL_FNAME ] = in_fi.fileName();
		else get_fname_fext( in_fi.fileName(), d_item_as_text.info[ COL_FNAME ], d_item_as_text.info[ COL_FEXT ] );
		get_size      ( in_fi.size(), d_item_as_text.info[ COL_SIZE ] );
		get_date_time ( in_fi.lastModified(), d_item_as_text.info[ COL_DATE ], d_item_as_text.info[ COL_TIME ] );

		d_item_as_text.info[ COL_OWNER ]  = in_fi.owner();
		d_item_as_text.info[ COL_GROUP ]  = in_fi.group();
		
		if( in_fi.isDir() ) emit next_dir();
		else emit next_file();
	}

	ViewTableItem* const item = create_tbl_item( d_item_as_text, FALSE );
	item->set_data( in_fi );
	add_dir_icon( item );
}
// wersja nr. 2 dla ftp
//----------------------
void ViewTable::display_item_info( const QUrlInfo& in_ui )
{
	d_item_as_text.clear();
	
	if( Shared::ParentDir == in_ui.name() ) {
		d_item_as_text.info[ COL_FNAME ] = Shared::ParentDir;
	}
	else {
		get_access( in_ui, d_item_as_text.info[ COL_ACCESS ] );
		if( 'd' == d_item_as_text.info[ COL_ACCESS ][0] ) d_item_as_text.info[ COL_FNAME ] = in_ui.name();
		else get_fname_fext( in_ui.name(), d_item_as_text.info[ COL_FNAME ], d_item_as_text.info[ COL_FEXT ] );
		get_size      ( in_ui.size()        , d_item_as_text.info[ COL_SIZE ] );
		get_date_time ( in_ui.lastModified(), d_item_as_text.info[ COL_DATE ], d_item_as_text.info[ COL_TIME ] );
		
		d_item_as_text.info[ COL_OWNER ]  = in_ui.owner();
		d_item_as_text.info[ COL_GROUP ]  = in_ui.group();
		
		if( in_ui.isDir() ) emit next_dir();
		else emit next_file();
	}

	ViewTableItem* const item = create_tbl_item( d_item_as_text, TRUE );
	item->set_data( in_ui );
	add_dir_icon( item );
}
// end of display_item_info

//*******************************************************************
// can_display                                               PRIVATE
//*******************************************************************
bool ViewTable::can_display( const QString& in_fname, const bool in_is_root )
{
	bool retval = TRUE;

	// Jednej kropki, THIS_DIR, nie wyswietlamy nigdy.
	if( Shared::ThisDir == in_fname ) {
		retval = FALSE;
	}
	// Normalnie dwukropek (PARENT_DIR) jest wyswietlamy.
	// Z wyjatkiem, gdy jestesmy w katalogu root (on nie ma katalogu parent).
	else if(( Shared::ParentDir == in_fname ) && in_is_root ) { 
		retval = FALSE;
	}

	return retval;
}
// end of can_display

//*******************************************************************
// get_fname_fext                                             PUBLIC
//*******************************************************************
void ViewTable::get_fname_fext( const QString& in_fname, QString& out_fname, QString& out_fext )
{
	if( Shared::ParentDir != in_fname ) {
		const int idx = in_fname.findRev( Shared::Point );
		if(( idx != -1 ) && ( idx != 0 )) {
			out_fname = in_fname.left( idx );
			out_fext = in_fname.mid( idx + 1 );
		}
		else {
			out_fname = in_fname;
			out_fext  = Shared::EmptyStr;
		}
	}
}
// end of get_fname_fext

//*******************************************************************
// get_sccess                                                PRIVATE
//*******************************************************************
// 1. lfs
//--------
void ViewTable::get_access( const QFileInfo& in_fi, QString& out_access )
{
	out_access = "----------";
	
	     if( in_fi.isDir()     ) out_access.at( 0 ) = 'd';
	else if( in_fi.isSymLink() ) out_access.at( 0 ) = 'l';

	if( in_fi.permission( QFileInfo::ReadUser   )) out_access.at( 1 ) = 'r';
	if( in_fi.permission( QFileInfo::WriteUser  )) out_access.at( 2 ) = 'w';
	if( in_fi.permission( QFileInfo::ExeUser    )) out_access.at( 3 ) = 'x';
	if( in_fi.permission( QFileInfo::ReadGroup  )) out_access.at( 4 ) = 'r';
	if( in_fi.permission( QFileInfo::WriteGroup )) out_access.at( 5 ) = 'w';
	if( in_fi.permission( QFileInfo::ExeGroup   )) out_access.at( 6 ) = 'x';
	if( in_fi.permission( QFileInfo::ReadOther  )) out_access.at( 7 ) = 'r';
	if( in_fi.permission( QFileInfo::WriteOther )) out_access.at( 8 ) = 'w';
	if( in_fi.permission( QFileInfo::ExeOther   )) out_access.at( 9 ) = 'x';
}
// 2. ftp
//--------
void ViewTable::get_access( const QUrlInfo& in_ui, QString& out_access )
{
	out_access = "----------";
	
	     if( in_ui.isDir()     ) out_access.at( 0 ) = 'd';
	else if( in_ui.isSymLink() ) out_access.at( 0 ) = 'l';

	if( in_ui.permissions() & QUrlInfo::ReadOwner  ) out_access.at( 1 ) = 'r';
	if( in_ui.permissions() & QUrlInfo::WriteOwner ) out_access.at( 2 ) = 'w';
	if( in_ui.permissions() & QUrlInfo::ExeOwner   ) out_access.at( 3 ) = 'x';
	if( in_ui.permissions() & QUrlInfo::ReadGroup  ) out_access.at( 4 ) = 'r';
	if( in_ui.permissions() & QUrlInfo::WriteGroup ) out_access.at( 5 ) = 'w';
	if( in_ui.permissions() & QUrlInfo::ExeGroup   ) out_access.at( 6 ) = 'x';
	if( in_ui.permissions() & QUrlInfo::ReadOther  ) out_access.at( 7 ) = 'r';
	if( in_ui.permissions() & QUrlInfo::WriteOther ) out_access.at( 8 ) = 'w';
	if( in_ui.permissions() & QUrlInfo::ExeOther   ) out_access.at( 9 ) = 'x';
}
// end of get_access

//*******************************************************************
// get_size                                                  PRIVATE
//*******************************************************************
inline void ViewTable::get_size( const unsigned int in_size, QString& out_size )
{
	out_size = Shared::num2str( in_size );
}
// end of get_size

//*******************************************************************
// get_date_time                                             PRIVATE
//*******************************************************************
void ViewTable::get_date_time( const QDateTime& in_dt, QString& out_date, QString& out_time )
{
	out_date = in_dt.date().toString( "yyyy-MM-dd" );
	out_time = in_dt.time().toString( "hh:mm:ss" );
}
// end of get_date_time


//###################################################################
//#                                                                 #
//#                           SLOTY                                 #
//#                                                                 #
//###################################################################


//*******************************************************************
// selection_changed                                    PRIVATE slot
//*******************************************************************
void ViewTable::selection_changed()
{
	static int number = 0;
	const int counter = get_selections_number();
	
	if( number != counter ) {
		emit selections_update( number = counter );
	}
}
// end of selection_changed

//*******************************************************************
// selection_mode_changed                               PRIVATE slot
//*******************************************************************
void ViewTable::selection_mode_changed()
{
	d_selection_mode = ( Config::NC == Config::instance()->selection_mode() ) ? Multi : Extended;
}
// end of selection_mode_changed

//*******************************************************************
// rightButtonClicked                              PRIVATE inherited
//*******************************************************************
void ViewTable::context_menu( QListViewItem*, const QPoint& in_pos, int )
{
	QPopupMenu* menu = new QPopupMenu( this );
	menu->setBackgroundMode( Qt::PaletteBackground );
	menu->setPaletteBackgroundColor( CTXMENU_BACKGROUND_COLOR );

	menu->insertItem( Shared::MenuAccess, this, SIGNAL( F2() ));
	menu->insertItem( Shared::MenuView  , this, SIGNAL( F3() ));
	menu->insertItem( Shared::MenuEdit  , this, SIGNAL( F4() ));
	menu->insertItem( Shared::MenuCopy  , this, SIGNAL( F5() ));
	menu->insertItem( Shared::MenuRename, this, SIGNAL( F6() ));
	menu->insertItem( Shared::MenuDelete, this, SIGNAL( F8() ));
	menu->insertItem( Shared::MenuPack  , this, SIGNAL( F9() ));
	menu->insertSeparator();
	menu->insertItem( Shared::MenuEmpty , this, SIGNAL( empty() ));

	menu->exec( in_pos );
	delete menu;
	menu = 0;
}
// end of rightButtonClicked

//*******************************************************************
// retranslate_strings                                  PRIVATE slot
//*******************************************************************
void ViewTable::retranslate_strings()
{
	for( int i = 0; i < COLUMNS; ++i ) {
		header()->setLabel( i, tr(COLDEF[i].name) );
	}
	adjust();
}
// end of retranslate_strings