1
/* This file is part of the KDE libraries
2
Copyright (C) 1997, 1998 Richard Moore <rich@kde.org>
3
1998 Stephan Kulow <coolo@kde.org>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
Boston, MA 02110-1301, USA.
24
#include <QtCore/QDir>
25
#include <QtGui/QLayout>
26
#include <QtCore/QMutableStringListIterator>
27
#include <QtGui/QWidget>
29
#include <kfiledialog.h>
30
#include <kmessagebox.h>
32
#include <kapplication.h>
33
#include <kcmdlineargs.h>
37
#include <kdiroperator.h>
41
#include <kicondialog.h>
44
#include <kconfiggroup.h>
46
int main(int argc, char **argv)
48
KCmdLineOptions options;
49
options.add("+[cmd]");
50
options.add("+[url]");
52
KCmdLineArgs::init(argc, argv, "kfstest", 0, ki18n("kfstest"), "0", ki18n("test app"));
53
KCmdLineArgs::addCmdLineOptions(options);
55
a.setQuitOnLastWindowClosed(false);
63
argv1 = QLatin1String(argv[1]);
65
startDir = KUrl( argv[2] );
68
if (argv1 == QLatin1String("diroperator")) {
69
KDirOperator *op = new KDirOperator(startDir, 0);
70
KConfigGroup grp(KGlobal::config(), "TestGroup" );
71
op->setViewConfig(grp);
72
op->setView(KFile::Simple);
77
if (argv1 == QLatin1String("localonly")) {
78
QString name = KFileDialog::getOpenFileName(startDir);
79
qDebug("filename=%s",name.toLatin1().constData());
81
else if (argv1 == QLatin1String("oneurl")) {
82
KUrl url = KFileDialog::getOpenUrl(startDir);
83
qDebug() << "url=" << url;
86
else if (argv1 == QLatin1String("existingDirectoryUrl")) {
87
KUrl url = KFileDialog::getExistingDirectoryUrl();
88
qDebug("URL=%s",url.url().toLatin1().constData());
92
else if (argv1 == QLatin1String("preview")) {
93
KUrl u = KFileDialog::getImageOpenUrl();
94
qDebug("filename=%s", u.url().toLatin1().constData());
97
else if (argv1 == QLatin1String("preselect")) {
98
names = KFileDialog::getOpenFileNames(KUrl("/etc/passwd"));
99
QStringList::Iterator it = names.begin();
100
while ( it != names.end() ) {
101
qDebug("selected file: %s", (*it).toLatin1().constData());
106
else if (argv1 == QLatin1String("dirs"))
107
name1 = KFileDialog::getExistingDirectory();
109
else if (argv1 == QLatin1String("heap")) {
110
KFileDialog *dlg = new KFileDialog( startDir, QString(), 0L);
111
dlg->setMode( KFile::File);
112
dlg->setOperationMode( KFileDialog::Saving );
114
filter << "all/allfiles" << "text/plain";
115
dlg->setMimeFilter( filter, "all/allfiles" );
117
KUrlBar *urlBar = dlg->speedBar();
120
urlBar->insertDynamicItem( KUrl("ftp://ftp.kde.org"),
121
QLatin1String("KDE FTP Server") );
124
if ( dlg->exec() == KDialog::Accepted )
125
name1 = dlg->selectedUrl().url();
128
else if ( argv1 == QLatin1String("eventloop") )
130
new KFDTest( startDir );
134
else if (argv1 == QLatin1String("save")) {
135
KUrl u = KFileDialog::getSaveUrl(startDir);
136
// QString(QDir::homePath() + QLatin1String("/testfile")),
141
else if (argv1 == QLatin1String("icon")) {
143
QString icon = dlg.getIcon();
147
// else if ( argv1 == QLatin1String("dirselect") ) {
149
// url.setPath( "/" );
150
// KUrl selected = KDirSelectDialog::selectDirectory( url );
151
// name1 = selected.url();
152
// qDebug("*** selected: %s", selected.url().toLatin1().constData());
156
KFileDialog dlg(startDir,
157
QString::fromLatin1("*|All Files\n"
158
"*.lo *.o *.la|All libtool Files"),0);
159
// dlg.setFilter( "*.kdevelop" );
160
dlg.setMode( KFile::Files |
162
KFile::ExistingOnly |
164
// QStringList filter;
165
// filter << "text/plain" << "text/html" << "image/png";
166
// dlg.setMimeFilter( filter );
167
// KMimeType::List types;
168
// types.append( KMimeType::mimeType( "text/plain" ) );
169
// types.append( KMimeType::mimeType( "text/html" ) );
170
// dlg.setFilterMimeType( "Filetypes:", types, types.first() );
171
if ( dlg.exec() == QDialog::Accepted ) {
172
const KUrl::List list = dlg.selectedUrls();
173
KUrl::List::ConstIterator it = list.constBegin();
174
qDebug("*** selectedUrls(): ");
175
while ( it != list.constEnd() ) {
177
qDebug(" -> %s", name1.toLatin1().constData());
180
qDebug("*** selectedFile: %s", dlg.selectedFile().toLatin1().constData());
181
qDebug("*** selectedUrl: %s", dlg.selectedUrl().url().toLatin1().constData());
182
qDebug("*** selectedFiles: ");
183
QStringList l = dlg.selectedFiles();
184
QStringList::Iterator it2 = l.begin();
185
while ( it2 != l.end() ) {
186
qDebug(" -> %s", (*it2).toLatin1().constData());
192
if (!(name1.isNull()))
193
KMessageBox::information(0, QLatin1String("You selected the file " ) + name1,
194
QLatin1String("Your Choice"));