File indexing completed on 2024-03-24 15:27:58
0001 /* This file is part of the KDE libraries 0002 Copyright (C) 1997, 1998 Richard Moore <rich@kde.org> 0003 1998 Stephan Kulow <coolo@kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #include <unistd.h> 0022 #include <stdlib.h> 0023 #include <sys/stat.h> 0024 #include <QDir> 0025 #include <QApplication> 0026 #include <QLayout> 0027 #include <QMutableStringListIterator> 0028 #include <QWidget> 0029 0030 #include <kfiledialog.h> 0031 #include <kmessagebox.h> 0032 #if 0 // SPLIT-TODO 0033 #include <kconfig.h> 0034 #include <kurlbar.h> 0035 #include <kdiroperator.h> 0036 #endif 0037 #include <kfile.h> 0038 #include <QDebug> 0039 #include <kicondialog.h> 0040 0041 #include "kfstest.h" 0042 #include <kconfiggroup.h> 0043 0044 #include <QMutableStringListIterator> 0045 #include <kfiledialog.h> 0046 #include <kmessagebox.h> 0047 #include <QTimer> 0048 0049 KFDTest::KFDTest(const QUrl &startDir, QObject *parent, const char *name) 0050 : QObject(parent), 0051 m_startDir(startDir) 0052 { 0053 setObjectName(name); 0054 QTimer::singleShot(1000, this, SLOT(doit())); 0055 } 0056 0057 void KFDTest::doit() 0058 { 0059 KFileDialog *dlg = new KFileDialog(m_startDir, QString(), nullptr); 0060 dlg->setMode(KFile::File); 0061 dlg->setOperationMode(KFileDialog::Saving); 0062 QStringList filter; 0063 filter << "application/octet-stream" << "text/plain"; 0064 dlg->setMimeFilter(filter, "application/octet-stream"); 0065 0066 if (dlg->exec() == QDialog::Accepted) { 0067 KMessageBox::information(nullptr, QString::fromLatin1("You selected the file: %1").arg(dlg->selectedUrl().toString())); 0068 } 0069 0070 // qApp->quit(); 0071 } 0072 0073 int main(int argc, char **argv) 0074 { 0075 //KCmdLineOptions options; 0076 //options.add("+[cmd]"); 0077 //options.add("+[url]"); 0078 0079 QApplication a(argc, argv); 0080 a.setQuitOnLastWindowClosed(false); 0081 0082 QString name1; 0083 QStringList names; 0084 0085 QString argv1; 0086 QUrl startDir; 0087 if (argc > 1) { 0088 argv1 = QLatin1String(argv[1]); 0089 } 0090 if (argc > 2) { 0091 startDir = QUrl::fromUserInput(argv[2]); 0092 } 0093 0094 #if 0 // SPLIT-TODO 0095 if (argv1 == QLatin1String("diroperator")) { 0096 KDirOperator *op = new KDirOperator(startDir, 0); 0097 KConfigGroup grp(KSharedConfig::openConfig(), "TestGroup"); 0098 op->setViewConfig(grp); 0099 op->setView(KFile::Simple); 0100 op->show(); 0101 a.exec(); 0102 } else 0103 #endif 0104 if (argv1 == QLatin1String("localonly")) { 0105 QString name = KFileDialog::getOpenFileName(startDir); 0106 qDebug("filename=%s", name.toLatin1().constData()); 0107 } else if (argv1 == QLatin1String("oneurl")) { 0108 QUrl url = KFileDialog::getOpenUrl(startDir); 0109 qDebug() << "url=" << url; 0110 } else if (argv1 == QLatin1String("multipleurls")) { 0111 QList<QUrl> urls = KFileDialog::getOpenUrls(startDir); 0112 qDebug() << "urls=" << QUrl::toStringList(urls); 0113 } else if (argv1 == QLatin1String("existingDirectoryUrl")) { 0114 QUrl url = KFileDialog::getExistingDirectoryUrl(); 0115 qDebug("URL=%s", url.toString().toLatin1().constData()); 0116 name1 = url.toString(); 0117 } 0118 0119 else if (argv1 == QLatin1String("preview")) { 0120 QUrl u = KFileDialog::getImageOpenUrl(); 0121 qDebug("filename=%s", u.toString().toLatin1().constData()); 0122 } 0123 0124 else if (argv1 == QLatin1String("preselect")) { 0125 names = KFileDialog::getOpenFileNames(QUrl::fromLocalFile("/etc/passwd")); 0126 QStringList::Iterator it = names.begin(); 0127 while (it != names.end()) { 0128 qDebug("selected file: %s", (*it).toLatin1().constData()); 0129 ++it; 0130 } 0131 } 0132 0133 else if (argv1 == QLatin1String("dirs")) { 0134 name1 = KFileDialog::getExistingDirectory(); 0135 } 0136 0137 else if (argv1 == QLatin1String("heap")) { 0138 KFileDialog *dlg = new KFileDialog(startDir, QString(), nullptr); 0139 dlg->setMode(KFile::File); 0140 dlg->setOperationMode(KFileDialog::Saving); 0141 QStringList filter; 0142 filter << "application/octet-stream" << "text/plain"; 0143 dlg->setMimeFilter(filter, "application/octet-stream"); 0144 #if 0 // SPLIT-TODO 0145 KUrlBar *urlBar = dlg->speedBar(); 0146 if (urlBar) { 0147 urlBar->insertDynamicItem(QUrl("ftp://ftp.kde.org"), 0148 QLatin1String("KDE FTP Server")); 0149 } 0150 #endif 0151 if (dlg->exec() == QDialog::Accepted) { 0152 name1 = dlg->selectedUrl().toString(); 0153 } 0154 } 0155 0156 else if (argv1 == QLatin1String("eventloop")) { 0157 new KFDTest(startDir); 0158 return a.exec(); 0159 } 0160 0161 else if (argv1 == QLatin1String("save")) { 0162 QUrl u = KFileDialog::getSaveUrl(startDir); 0163 // QString(QDir::homePath() + QLatin1String("/testfile")), 0164 // QString(), 0L); 0165 name1 = u.toString(); 0166 } 0167 0168 else if (argv1 == QLatin1String("icon")) { 0169 KIconDialog dlg; 0170 QString icon = dlg.getIcon(); 0171 qDebug() << icon; 0172 } 0173 0174 // else if ( argv1 == QLatin1String("dirselect") ) { 0175 // QUrl url = QUrl::fromLocalFile("/"); 0176 // QUrl selected = KDirSelectDialog::selectDirectory( url ); 0177 // name1 = selected.toString(); 0178 // qDebug("*** selected: %s", selected.toString().toLatin1().constData()); 0179 // } 0180 0181 else { 0182 KFileDialog dlg(startDir, 0183 QString::fromLatin1("*|All Files\n" 0184 "*.lo *.o *.la|All libtool Files"), nullptr); 0185 // dlg.setFilter( "*.kdevelop" ); 0186 dlg.setMode(KFile::Files | 0187 KFile::Directory | 0188 KFile::ExistingOnly | 0189 KFile::LocalOnly); 0190 // QStringList filter; 0191 // filter << "text/plain" << "text/html" << "image/png"; 0192 // dlg.setMimeFilter( filter ); 0193 // KMimeType::List types; 0194 // types.append( KMimeType::mimeType( "text/plain" ) ); 0195 // types.append( KMimeType::mimeType( "text/html" ) ); 0196 // dlg.setFilterMimeType( "Filetypes:", types, types.first() ); 0197 if (dlg.exec() == QDialog::Accepted) { 0198 const QList<QUrl> list = dlg.selectedUrls(); 0199 QList<QUrl>::ConstIterator it = list.constBegin(); 0200 qDebug("*** selectedUrls(): "); 0201 while (it != list.constEnd()) { 0202 name1 = (*it).toString(); 0203 qDebug(" -> %s", name1.toLatin1().constData()); 0204 ++it; 0205 } 0206 qDebug("*** selectedFile: %s", dlg.selectedFile().toLatin1().constData()); 0207 qDebug("*** selectedUrl: %s", dlg.selectedUrl().toString().toLatin1().constData()); 0208 qDebug("*** selectedFiles: "); 0209 QStringList l = dlg.selectedFiles(); 0210 QStringList::Iterator it2 = l.begin(); 0211 while (it2 != l.end()) { 0212 qDebug(" -> %s", (*it2).toLatin1().constData()); 0213 ++it2; 0214 } 0215 } 0216 } 0217 0218 if (!(name1.isNull())) 0219 KMessageBox::information(nullptr, QLatin1String("You selected the file ") + name1, 0220 QLatin1String("Your Choice")); 0221 return 0; 0222 } 0223 0224 #include "moc_kfstest.cpp"