summaryrefslogtreecommitdiffabout
path: root/microkde/kio/kfile/kurlrequester.cpp
Unidiff
Diffstat (limited to 'microkde/kio/kfile/kurlrequester.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kio/kfile/kurlrequester.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/microkde/kio/kfile/kurlrequester.cpp b/microkde/kio/kfile/kurlrequester.cpp
index ca94570..ce62da7 100644
--- a/microkde/kio/kfile/kurlrequester.cpp
+++ b/microkde/kio/kfile/kurlrequester.cpp
@@ -1,316 +1,318 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright (C) 1999,2000,2001 Carsten Pfeiffer <pfeiffer@kde.org> 2 Copyright (C) 1999,2000,2001 Carsten Pfeiffer <pfeiffer@kde.org>
3 3
4 library is free software; you can redistribute it and/or 4 library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public 5 modify it under the terms of the GNU Library General Public
6 License version 2, as published by the Free Software Foundation. 6 License version 2, as published by the Free Software Foundation.
7 7
8 This library is distributed in the hope that it will be useful, 8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of 9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details. 11 Library General Public License for more details.
12 12
13 You should have received a copy of the GNU Library General Public License 13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to 14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA. 16 Boston, MA 02111-1307, USA.
17*/ 17*/
18 18
19 19
20#include <sys/stat.h> 20#include <sys/stat.h>
21#ifdef _WIN32_ 21#ifdef _WIN32_
22 22
23#else 23#else
24#include <unistd.h> 24#include <unistd.h>
25#endif 25#endif
26#include <qstring.h> 26#include <qstring.h>
27//US #include <qtooltip.h> 27//US #include <qtooltip.h>
28 28
29#include <qpushbutton.h> 29#include <qpushbutton.h>
30//Added by qt3to4:
31#include <QPixmap>
30 32
31//US #include <kaccel.h> 33//US #include <kaccel.h>
32//US #include <kcombobox.h> 34//US #include <kcombobox.h>
33#include <kdebug.h> 35#include <kdebug.h>
34#include <kdialog.h> 36#include <kdialog.h>
35#include <kfiledialog.h> 37#include <kfiledialog.h>
36#include <kglobal.h> 38#include <kglobal.h>
37#include <kiconloader.h> 39#include <kiconloader.h>
38#include <klineedit.h> 40#include <klineedit.h>
39#include <klocale.h> 41#include <klocale.h>
40//US #include <kurlcompletion.h> 42//US #include <kurlcompletion.h>
41//US #include <kurldrag.h> 43//US #include <kurldrag.h>
42//US #include <kprotocolinfo.h> 44//US #include <kprotocolinfo.h>
43 45
44 46
45#include "kurlrequester.h" 47#include "kurlrequester.h"
46 48
47 49
48class KURLDragPushButton : public QPushButton 50class KURLDragPushButton : public QPushButton
49{ 51{
50public: 52public:
51 KURLDragPushButton( QWidget *parent, const char *name=0 ) 53 KURLDragPushButton( QWidget *parent, const char *name=0 )
52 : QPushButton( parent, name ) { 54 : QPushButton( parent, name ) {
53 //US setDragEnabled( true ); 55 //US setDragEnabled( true );
54 } 56 }
55 ~KURLDragPushButton() {} 57 ~KURLDragPushButton() {}
56 58
57 void setURL( const KURL& url ) { 59 void setURL( const KURL& url ) {
58 m_urls.clear(); 60 m_urls.clear();
59 m_urls.append( url ); 61 m_urls.append( url );
60 } 62 }
61 63
62 /* not needed so far 64 /* not needed so far
63 void setURLs( const KURL::List& urls ) { 65 void setURLs( const KURL::List& urls ) {
64 m_urls = urls; 66 m_urls = urls;
65 } 67 }
66 const KURL::List& urls() const { return m_urls; } 68 const KURL::List& urls() const { return m_urls; }
67 */ 69 */
68 70
69protected: 71protected:
70/*US 72/*US
71 virtual QDragObject *dragObject() { 73 virtual QDragObject *dragObject() {
72 if ( m_urls.isEmpty() ) 74 if ( m_urls.isEmpty() )
73 return 0L; 75 return 0L;
74 76
75 QDragObject *drag = KURLDrag::newDrag( m_urls, this, "url drag" ); 77 QDragObject *drag = KURLDrag::newDrag( m_urls, this, "url drag" );
76 return drag; 78 return drag;
77 } 79 }
78*/ 80*/
79private: 81private:
80 KURL::List m_urls; 82 KURL::List m_urls;
81 83
82}; 84};
83 85
84 86
85/* 87/*
86************************************************************************* 88*************************************************************************
87*/ 89*/
88 90
89class KURLRequester::KURLRequesterPrivate 91class KURLRequester::KURLRequesterPrivate
90{ 92{
91public: 93public:
92 KURLRequesterPrivate() { 94 KURLRequesterPrivate() {
93 edit = 0L; 95 edit = 0L;
94 //UScombo = 0L; 96 //UScombo = 0L;
95//US fileDialogMode = KFile::File | KFile::ExistingOnly | KFile::LocalOnly; 97//US fileDialogMode = KFile::File | KFile::ExistingOnly | KFile::LocalOnly;
96 } 98 }
97 99
98 void setText( const QString& text ) { 100 void setText( const QString& text ) {
99/*US 101/*US
100 if ( combo ) 102 if ( combo )
101 { 103 {
102 if (combo->editable()) 104 if (combo->editable())
103 { 105 {
104 combo->setEditText( text ); 106 combo->setEditText( text );
105 } 107 }
106 else 108 else
107 { 109 {
108 combo->insertItem( text ); 110 combo->insertItem( text );
109 combo->setCurrentItem( combo->count()-1 ); 111 combo->setCurrentItem( combo->count()-1 );
110 } 112 }
111 } 113 }
112 else 114 else
113*/ 115*/
114 { 116 {
115 edit->setText( text ); 117 edit->setText( text );
116 } 118 }
117 } 119 }
118 120
119 void connectSignals( QObject *receiver ) { 121 void connectSignals( QObject *receiver ) {
120 QObject *sender; 122 QObject *sender;
121 /*USif ( combo ) 123 /*USif ( combo )
122 sender = combo; 124 sender = combo;
123 else 125 else
124*/ 126*/
125 sender = edit; 127 sender = edit;
126 128
127 connect( sender, SIGNAL( textChanged( const QString& )), 129 connect( sender, SIGNAL( textChanged( const QString& )),
128 receiver, SIGNAL( textChanged( const QString& ))); 130 receiver, SIGNAL( textChanged( const QString& )));
129 connect( sender, SIGNAL( returnPressed() ), 131 connect( sender, SIGNAL( returnPressed() ),
130 receiver, SIGNAL( returnPressed() )); 132 receiver, SIGNAL( returnPressed() ));
131 //USconnect( sender, SIGNAL( returnPressed( const QString& ) ), 133 //USconnect( sender, SIGNAL( returnPressed( const QString& ) ),
132 //US receiver, SIGNAL( returnPressed( const QString& ) )); 134 //US receiver, SIGNAL( returnPressed( const QString& ) ));
133 } 135 }
134/*US 136/*US
135 void setCompletionObject( KCompletion *comp ) { 137 void setCompletionObject( KCompletion *comp ) {
136 if ( combo ) 138 if ( combo )
137 combo->setCompletionObject( comp ); 139 combo->setCompletionObject( comp );
138 else 140 else
139 edit->setCompletionObject( comp ); 141 edit->setCompletionObject( comp );
140 } 142 }
141 */ 143 */
142 /** 144 /**
143 * replaces ~user or $FOO, if necessary 145 * replaces ~user or $FOO, if necessary
144 */ 146 */
145 QString url() { 147 QString url() {
146 QString txt = /*US combo ? combo->currentText() : */ edit->text(); 148 QString txt = /*US combo ? combo->currentText() : */ edit->text();
147/*US KURLCompletion *comp; 149/*US KURLCompletion *comp;
148 if ( combo ) 150 if ( combo )
149 comp = dynamic_cast<KURLCompletion*>(combo->completionObject()); 151 comp = dynamic_cast<KURLCompletion*>(combo->completionObject());
150 else 152 else
151 comp = dynamic_cast<KURLCompletion*>(edit->completionObject()); 153 comp = dynamic_cast<KURLCompletion*>(edit->completionObject());
152 154
153 if ( comp ) 155 if ( comp )
154 return comp->replacedPath( txt ); 156 return comp->replacedPath( txt );
155 else 157 else
156*/ 158*/
157 return txt; 159 return txt;
158 } 160 }
159 161
160 KLineEdit *edit; 162 KLineEdit *edit;
161//US KComboBox *combo; 163//US KComboBox *combo;
162 int fileDialogMode; 164 int fileDialogMode;
163 QString fileDialogFilter; 165 QString fileDialogFilter;
164}; 166};
165 167
166 168
167/*US 169/*US
168KURLRequester::KURLRequester( QWidget *editWidget, QWidget *parent, 170KURLRequester::KURLRequester( QWidget *editWidget, QWidget *parent,
169 const char *name ) 171 const char *name )
170 : QHBox( parent, name ) 172 : QHBox( parent, name )
171{ 173{
172 d = new KURLRequesterPrivate; 174 d = new KURLRequesterPrivate;
173 175
174 // must have this as parent 176 // must have this as parent
175 editWidget->reparent( this, 0, QPoint(0,0) ); 177 editWidget->reparent( this, 0, QPoint(0,0) );
176//US d->edit = dynamic_cast<KLineEdit*>( editWidget ); 178//US d->edit = dynamic_cast<KLineEdit*>( editWidget );
177 d->edit = (KLineEdit*)( editWidget ); 179 d->edit = (KLineEdit*)( editWidget );
178//US d->combo = dynamic_cast<KComboBox*>( editWidget ); 180//US d->combo = dynamic_cast<KComboBox*>( editWidget );
179 181
180 init(); 182 init();
181} 183}
182*/ 184*/
183 185
184KURLRequester::KURLRequester( QWidget *parent, const char *name ) 186KURLRequester::KURLRequester( QWidget *parent, const char *name )
185 : QHBox( parent, name ) 187 : Q3HBox( parent, name )
186{ 188{
187 d = new KURLRequesterPrivate; 189 d = new KURLRequesterPrivate;
188 init(); 190 init();
189} 191}
190 192
191 193
192KURLRequester::KURLRequester( const QString& url, QWidget *parent, 194KURLRequester::KURLRequester( const QString& url, QWidget *parent,
193 const char *name ) 195 const char *name )
194 : QHBox( parent, name ) 196 : Q3HBox( parent, name )
195{ 197{
196 d = new KURLRequesterPrivate; 198 d = new KURLRequesterPrivate;
197 init(); 199 init();
198 setURL( url ); 200 setURL( url );
199} 201}
200 202
201 203
202KURLRequester::~KURLRequester() 204KURLRequester::~KURLRequester()
203{ 205{
204//US delete myCompletion; 206//US delete myCompletion;
205 delete myFileDialog; 207 delete myFileDialog;
206 delete d; 208 delete d;
207} 209}
208 210
209 211
210void KURLRequester::init() 212void KURLRequester::init()
211{ 213{
212 myFileDialog = 0L; 214 myFileDialog = 0L;
213 myShowLocalProt = false; 215 myShowLocalProt = false;
214 mPathIsDir = false; 216 mPathIsDir = false;
215 if (/*US !d->combo && */ !d->edit ) 217 if (/*US !d->combo && */ !d->edit )
216 d->edit = new KLineEdit( this, "KURLRequester::KLineEdit" ); 218 d->edit = new KLineEdit( this, "KURLRequester::KLineEdit" );
217 219
218 myButton = new KURLDragPushButton( this, "kfile button"); 220 myButton = new KURLDragPushButton( this, "kfile button");
219 QIconSet iconSet = SmallIconSet("fileopen"); 221 QIcon iconSet = SmallIconSet("fileopen");
220 QPixmap pixMap = iconSet.pixmap( QIconSet::Small, QIconSet::Normal ); 222 QPixmap pixMap = iconSet.pixmap( QIcon::Small, QIcon::Normal );
221 myButton->setIconSet( iconSet ); 223 myButton->setIconSet( iconSet );
222 myButton->setFixedSize( pixMap.width()+8, pixMap.height()+8 ); 224 myButton->setFixedSize( pixMap.width()+8, pixMap.height()+8 );
223//US QToolTip::add(myButton, i18n("Open file dialog")); 225//US QToolTip::add(myButton, i18n("Open file dialog"));
224 226
225 connect( myButton, SIGNAL( pressed() ), SLOT( slotUpdateURL() )); 227 connect( myButton, SIGNAL( pressed() ), SLOT( slotUpdateURL() ));
226 228
227 setSpacing( KDialog::spacingHint() ); 229 setSpacing( KDialog::spacingHint() );
228 230
229 QWidget *widget = /*US d->combo ? (QWidget*) d->combo : */ (QWidget*) d->edit; 231 QWidget *widget = /*US d->combo ? (QWidget*) d->combo : */ (QWidget*) d->edit;
230 setFocusProxy( widget ); 232 setFocusProxy( widget );
231 233
232 d->connectSignals( this ); 234 d->connectSignals( this );
233 connect( myButton, SIGNAL( clicked() ), this, SLOT( slotOpenDialog() )); 235 connect( myButton, SIGNAL( clicked() ), this, SLOT( slotOpenDialog() ));
234/*US 236/*US
235 myCompletion = new KURLCompletion(); 237 myCompletion = new KURLCompletion();
236 d->setCompletionObject( myCompletion ); 238 d->setCompletionObject( myCompletion );
237 239
238 KAccel *accel = new KAccel( this ); 240 KAccel *accel = new KAccel( this );
239 accel->insert( KStdAccel::Open, this, SLOT( slotOpenDialog() )); 241 accel->insert( KStdAccel::Open, this, SLOT( slotOpenDialog() ));
240 accel->readSettings(); 242 accel->readSettings();
241*/ 243*/
242} 244}
243 245
244 246
245void KURLRequester::setURL( const QString& url ) 247void KURLRequester::setURL( const QString& url )
246{ 248{
247 bool hasLocalPrefix = (url.startsWith("file:")); 249 bool hasLocalPrefix = (url.startsWith("file:"));
248 250
249 if ( !myShowLocalProt && hasLocalPrefix ) 251 if ( !myShowLocalProt && hasLocalPrefix )
250 d->setText( url.mid( 5, url.length()-5 )); 252 d->setText( url.mid( 5, url.length()-5 ));
251 else 253 else
252 d->setText( url ); 254 d->setText( url );
253} 255}
254 256
255void KURLRequester::setCaption( const QString& caption ) 257void KURLRequester::setCaption( const QString& caption )
256{ 258{
257 //USfileDialog()->setCaption( caption ); 259 //USfileDialog()->setCaption( caption );
258 //USQWidget::setCaption( caption ); 260 //USQWidget::setCaption( caption );
259} 261}
260 262
261QString KURLRequester::url() const 263QString KURLRequester::url() const
262{ 264{
263 return d->url(); 265 return d->url();
264} 266}
265 267
266 268
267void KURLRequester::slotOpenDialog() 269void KURLRequester::slotOpenDialog()
268{ 270{
269 emit openFileDialog( this ); 271 emit openFileDialog( this );
270 272
271//US use our special KFIleDialog instead 273//US use our special KFIleDialog instead
272 KURL u( url() ); 274 KURL u( url() );
273 //QString fn = u.url(); 275 //QString fn = u.url();
274 QString fn = d->edit->text(); 276 QString fn = d->edit->text();
275 if ( mPathIsDir ) 277 if ( mPathIsDir )
276 fn = KFileDialog::getExistingDirectory ( fn, "", this ); 278 fn = KFileDialog::getExistingDirectory ( fn, "", this );
277 else 279 else
278 fn = KFileDialog::getSaveFileName( fn, "", this ); 280 fn = KFileDialog::getSaveFileName( fn, "", this );
279 281
280 if ( fn == "" ) 282 if ( fn == "" )
281 return; 283 return;
282 284
283 setURL( fn ); 285 setURL( fn );
284 emit urlSelected( d->url() ); 286 emit urlSelected( d->url() );
285/*US 287/*US
286 KFileDialog *dlg = fileDialog(); 288 KFileDialog *dlg = fileDialog();
287 if ( !d->url().isEmpty() ) { 289 if ( !d->url().isEmpty() ) {
288 KURL u( url() ); 290 KURL u( url() );
289 // If we won't be able to list it (e.g. http), then don't try :) 291 // If we won't be able to list it (e.g. http), then don't try :)
290 if ( KProtocolInfo::supportsListing( u.protocol() ) ) 292 if ( KProtocolInfo::supportsListing( u.protocol() ) )
291 dlg->setSelection( u.url() ); 293 dlg->setSelection( u.url() );
292 } 294 }
293 295
294 if ( dlg->exec() == QDialog::Accepted ) 296 if ( dlg->exec() == QDialog::Accepted )
295 { 297 {
296 setURL( dlg->selectedURL().prettyURL() ); 298 setURL( dlg->selectedURL().prettyURL() );
297 emit urlSelected( d->url() ); 299 emit urlSelected( d->url() );
298 } 300 }
299*/ 301*/
300 302
301} 303}
302 304
303void KURLRequester::setMode(unsigned int mode) 305void KURLRequester::setMode(unsigned int mode)
304{ 306{
305/*US 307/*US
306 Q_ASSERT( (mode & KFile::Files) == 0 ); 308 Q_ASSERT( (mode & KFile::Files) == 0 );
307 d->fileDialogMode = mode; 309 d->fileDialogMode = mode;
308 if ( (mode & KFile::Directory) && !(mode & KFile::File) ) 310 if ( (mode & KFile::Directory) && !(mode & KFile::File) )
309 myCompletion->setMode( KURLCompletion::DirCompletion ); 311 myCompletion->setMode( KURLCompletion::DirCompletion );
310 312
311 if (myFileDialog) 313 if (myFileDialog)
312 myFileDialog->setMode( d->fileDialogMode ); 314 myFileDialog->setMode( d->fileDialogMode );
313*/ 315*/
314} 316}
315 317
316void KURLRequester::setFilter(const QString &filter) 318void KURLRequester::setFilter(const QString &filter)