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
|
/* This file is part of the KDE libraries
Copyright (C) 2001 Klaas Freitag <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <tqdir.h>
#include <kglobal.h>
#include <kiconloader.h>
#include <tdemainwindow.h>
#include <kapplication.h>
#include <kurl.h>
#include <kdebug.h>
#include <kstatusbar.h>
#include <tdefiletreeview.h>
#include "tdefiletreeviewtest.h"
#include "tdefiletreeviewtest.moc"
testFrame::testFrame():TDEMainWindow(0,"Test FileTreeView"),
dirOnlyMode(false)
{
treeView = new KFileTreeView( this );
treeView->setDragEnabled( true );
treeView->setAcceptDrops( true );
treeView->setDropVisualizer( true );
/* Connect to see the status bar */
KStatusBar* sta = statusBar();
connect( treeView, TQT_SIGNAL( onItem( const TQString& )),
sta, TQT_SLOT( message( const TQString& )));
connect( treeView, TQT_SIGNAL( dropped( TQWidget*, TQDropEvent*, KURL::List& )),
this, TQT_SLOT( urlsDropped( TQWidget*, TQDropEvent*, KURL::List& )));
connect( treeView, TQT_SIGNAL( dropped( KURL::List&, KURL& )), this,
TQT_SLOT( copyURLs( KURL::List&, KURL& )));
treeView->addColumn( "File" );
treeView->addColumn( "ChildCount" );
setCentralWidget( treeView );
resize( 600, 400 );
showPath( KURL::fromPathOrURL( TQDir::homeDirPath() ));
}
void testFrame::showPath( const KURL &url )
{
TQString fname = "TestBranch"; // url.fileName ();
/* try a user icon */
TDEIconLoader *loader = TDEGlobal::iconLoader();
TQPixmap pix = loader->loadIcon( "contents2", TDEIcon::Small );
TQPixmap pixOpen = loader->loadIcon( "contents", TDEIcon::Small );
KFileTreeBranch *nb = treeView->addBranch( url, fname, pix );
if( nb )
{
if( dirOnlyMode ) treeView->setDirOnlyMode( nb, true );
nb->setOpenPixmap( pixOpen );
connect( nb, TQT_SIGNAL(populateFinished(KFileTreeViewItem*)),
this, TQT_SLOT(slotPopulateFinished(KFileTreeViewItem*)));
connect( nb, TQT_SIGNAL( directoryChildCount( KFileTreeViewItem *, int )),
this, TQT_SLOT( slotSetChildCount( KFileTreeViewItem*, int )));
// nb->setChildRecurse(false );
nb->setOpen(true);
}
}
void testFrame::urlsDropped( TQWidget* , TQDropEvent* , KURL::List& list )
{
KURL::List::ConstIterator it = list.begin();
for ( ; it != list.end(); ++it ) {
kdDebug() << "Url dropped: " << (*it).prettyURL() << endl;
}
}
void testFrame::copyURLs( KURL::List& list, KURL& to )
{
KURL::List::ConstIterator it = list.begin();
kdDebug() << "Copy to " << to.prettyURL() << endl;
for ( ; it != list.end(); ++it ) {
kdDebug() << "Url: " << (*it).prettyURL() << endl;
}
}
void testFrame::slotPopulateFinished(KFileTreeViewItem *item )
{
if( item )
{
#if 0
int cc = item->childCount();
kdDebug() << "setting column 2 of treeview with count " << cc << endl;
item->setText( 1, TQString::number( cc ));
#endif
}
else
{
kdDebug() << "slotPopFinished for uninitalised item" << endl;
}
}
void testFrame::slotSetChildCount( KFileTreeViewItem *item, int c )
{
if( item )
item->setText(1, TQString::number( c ));
}
int main(int argc, char **argv)
{
TDEApplication a(argc, argv, "tdefiletreeviewtest");
TQString name1;
TQStringList names;
TQString argv1;
testFrame *tf;
tf = new testFrame();
a.setMainWidget( tf );
if (argc > 1)
{
for( int i = 1; i < argc; i++ )
{
argv1 = TQString::fromLatin1(argv[i]);
kdDebug() << "Opening " << argv1 << endl;
if( argv1 == "-d" )
tf->setDirOnly();
else
{
KURL u( argv1 );
tf->showPath( u );
}
}
}
tf->show();
int ret = a.exec();
return( ret );
}
|