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
|
/****************************************************************************
* Copyright (C) 2001 by Hugo Varotto *
* [email protected] *
* *
* Based on Kate's fileselector widget by *
* Matt Newell *
* (C) 2001 by Matt Newell *
* [email protected] *
* *
* This program 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 *
* *
***************************************************************************/
#include <qlayout.h>
#include <qpushbutton.h>
#include <qhbox.h>
#include <qlabel.h>
#include <qstrlist.h>
#include <qtooltip.h>
#include <qregexp.h>
#include <kxmlguiclient.h>
#include <kiconloader.h>
#include <kurlcombobox.h>
#include <kurlcompletion.h>
#include <kprotocolinfo.h>
#include <kconfig.h>
#include <klocale.h>
#include <kcombobox.h>
#include <kdebug.h>
#include "fileselectorwidget.h"
#include <kdiroperator.h>
#include <kcombiview.h>
#include <kfilepreview.h>
#include <kfileview.h>
#include <kfileitem.h>
#include <kimagefilepreview.h>
#include "autoprojectwidget.h"
#include "autoprojectpart.h"
#include "kdevlanguagesupport.h"
#include "kfilednddetailview.h"
#include "kfiledndiconview.h"
KDnDDirOperator::KDnDDirOperator ( const KURL &urlName, QWidget* parent, const char* name ) : KDirOperator ( urlName, parent, name )
{
}
KFileView* KDnDDirOperator::createView( QWidget* parent, KFile::FileView view )
{
KFileView* new_view = 0L;
if( (view & KFile::Detail) == KFile::Detail ) {
new_view = new KFileDnDDetailView( parent, "detail view");
}
else if ((view & KFile::Simple) == KFile::Simple ) {
new_view = new KFileDnDIconView( parent, "simple view");
new_view->setViewName( i18n("Short View") );
}
return new_view;
}
FileSelectorWidget::FileSelectorWidget(AutoProjectPart* part, KFile::Mode mode, QWidget* parent, const char* name ) : QWidget(parent, name)
{
m_part = part;
// widgets and layout
QVBoxLayout* lo = new QVBoxLayout(this);
QHBox *hlow = new QHBox (this);
lo->addWidget(hlow);
home = new QPushButton( hlow );
home->setPixmap(SmallIcon("gohome"));
QToolTip::add(home, i18n("Home directory"));
up = new QPushButton( /*i18n("&Up"),*/ hlow );
up->setPixmap(SmallIcon("up"));
QToolTip::add(up, i18n("Up one level"));
back = new QPushButton( /*i18n("&Back"),*/ hlow );
back->setPixmap(SmallIcon("back"));
QToolTip::add(back, i18n("Previous directory"));
forward = new QPushButton( /*i18n("&Next"),*/ hlow );
forward->setPixmap(SmallIcon("forward"));
QToolTip::add(forward, i18n("Next directory"));
// HACK
QWidget* spacer = new QWidget(hlow);
hlow->setStretchFactor(spacer, 1);
hlow->setMaximumHeight(up->height());
cmbPath = new KURLComboBox( KURLComboBox::Directories, true, this, "path combo" );
cmbPath->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ));
KURLCompletion* cmpl = new KURLCompletion();
cmbPath->setCompletionObject( cmpl );
lo->addWidget(cmbPath);
dir = new KDnDDirOperator(KURL(), this, "operator");
dir->setView(KFile::Simple);
dir->setMode(mode);
lo->addWidget(dir);
lo->setStretchFactor(dir, 2);
QHBox* filterBox = new QHBox(this);
filterIcon = new QLabel(filterBox);
filterIcon->setPixmap( BarIcon("filter") );
filter = new KHistoryCombo(filterBox, "filter");
filter->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ));
filterBox->setStretchFactor(filter, 2);
lo->addWidget(filterBox);
// slots and signals
connect( filter, SIGNAL( textChanged(const QString&) ), SLOT( slotFilterChanged(const QString&) ) );
connect( filter, SIGNAL( activated(const QString&) ), SLOT( slotFilterChanged(const QString&) ) );
connect( filter, SIGNAL( returnPressed(const QString&) ), SLOT( filterReturnPressed(const QString&) ) );
connect( home, SIGNAL( clicked() ), dir, SLOT( home() ) );
connect( up, SIGNAL( clicked() ), dir, SLOT( cdUp() ) );
connect( back, SIGNAL( clicked() ), dir, SLOT( back() ) );
connect( forward, SIGNAL( clicked() ), dir, SLOT( forward() ) );
connect( cmbPath, SIGNAL( urlActivated( const KURL& )), this, SLOT( cmbPathActivated( const KURL& ) ));
//connect( cmbPath, SIGNAL( returnPressed( const QString& )), this, SLOT( cmbPathReturnPressed( const QString& ) ));
connect( dir, SIGNAL(urlEntered(const KURL&)), this, SLOT(dirUrlEntered(const KURL&)) );
connect( dir, SIGNAL(finishedLoading()), this, SLOT(dirFinishedLoading()) );
// dirUrlEntered( dir->url() );
QStringList list;
/* read the file patterns from the project DOM */
QDomElement docEl = m_part->projectDom()->documentElement();
QDomElement fileviewEl = docEl.namedItem("kdevfileview").toElement();
QDomElement groupsEl = fileviewEl.namedItem("groups").toElement();
QDomElement groupEl = groupsEl.firstChild().toElement();
while ( !groupEl.isNull() )
{
if (groupEl.tagName() == "group")
{
list << groupEl.attribute("pattern").replace ( QRegExp ( ";" ), " " ) + " (" + groupEl.attribute("name") + ")";
}
groupEl = groupEl.nextSibling().toElement();
}
filter->setHistoryItems ( list );
}
FileSelectorWidget::~FileSelectorWidget()
{
}
void FileSelectorWidget::dragEnterEvent ( QDragEnterEvent* /*ev*/ )
{
}
void FileSelectorWidget::dropEvent ( QDropEvent* /*ev*/ )
{
kdDebug ( 9020 ) << "Dropped" << endl;
QString path = "Something was dropped in the Destination directory file-selector";
emit dropped ( path );
}
void FileSelectorWidget::filterReturnPressed ( const QString& nf )
{
// KURL u ( m_part->project()->projectDirectory() );
setDir ( nf );
}
void FileSelectorWidget::slotFilterChanged( const QString & nf )
{
dir->setNameFilter( nf );
dir->updateDir();
}
void FileSelectorWidget::cmbPathActivated( const KURL& u )
{
dir->setURL( u, true );
}
void FileSelectorWidget::cmbPathReturnPressed( const QString& u )
{
dir->setFocus();
dir->setURL( KURL(u), true );
}
void FileSelectorWidget::dirUrlEntered( const KURL& u )
{
cmbPath->removeURL( u );
QStringList urls = cmbPath->urls();
urls.prepend( u.url() );
while ( urls.count() >= (uint)cmbPath->maxItems() )
urls.remove( urls.last() );
cmbPath->setURLs( urls );
}
void FileSelectorWidget::dirFinishedLoading()
{
// HACK - enable the nav buttons
// have to wait for diroperator...
up->setEnabled( dir->actionCollection()->action( "up" )->isEnabled() );
back->setEnabled( dir->actionCollection()->action( "back" )->isEnabled() );
forward->setEnabled( dir->actionCollection()->action( "forward" )->isEnabled() );
home->setEnabled( dir->actionCollection()->action( "home" )->isEnabled() );
}
void FileSelectorWidget::focusInEvent(QFocusEvent*)
{
dir->setFocus();
}
void FileSelectorWidget::setDir( KURL u )
{
dir->setURL(u, true);
}
void FileSelectorWidget::setDir(const QString& path)
{
KURL u ( path );
dir->setURL ( u, true );
}
#include "fileselectorwidget.moc"
|