File indexing completed on 2024-04-21 15:02:45
0001 /* 0002 SPDX-FileCopyrightText: 2009 David Faure <faure@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include <QApplication> 0008 #include <QDebug> 0009 #include <browseropenorsavequestion.h> 0010 0011 using namespace KParts; 0012 0013 int main(int argc, char **argv) 0014 { 0015 QApplication::setApplicationName(QStringLiteral("openorsavequestion")); 0016 QApplication app(argc, argv); 0017 0018 // A test for both 1) "unknown mimetype" 2) no associated app 0019 { 0020 BrowserOpenOrSaveQuestion questionOpenUnknownMimeType(nullptr, 0021 QUrl(QStringLiteral("http://www.example.com/foo.foo")), 0022 QString::fromLatin1("application/foo")); 0023 BrowserOpenOrSaveQuestion::Result res = questionOpenUnknownMimeType.askOpenOrSave(); 0024 qDebug() << res; 0025 } 0026 0027 // The normal case 0028 { 0029 BrowserOpenOrSaveQuestion questionOpen(nullptr, QUrl(QStringLiteral("http://www.example.com/foo.pdf")), QString::fromLatin1("application/pdf")); 0030 questionOpen.setSuggestedFileName(QString::fromLatin1("file.pdf")); 0031 questionOpen.setFeatures(BrowserOpenOrSaveQuestion::ServiceSelection); 0032 BrowserOpenOrSaveQuestion::Result res = questionOpen.askOpenOrSave(); 0033 qDebug() << res; 0034 if (res == BrowserOpenOrSaveQuestion::Open && questionOpen.selectedService()) { 0035 qDebug() << "Selected service:" << questionOpen.selectedService()->entryPath(); 0036 } 0037 } 0038 0039 // Trying a case with only one app associated 0040 { 0041 BrowserOpenOrSaveQuestion questionOpen(nullptr, QUrl(QStringLiteral("http://www.example.com/foo.zip")), QString::fromLatin1("application/zip")); 0042 questionOpen.setFeatures(BrowserOpenOrSaveQuestion::ServiceSelection); 0043 BrowserOpenOrSaveQuestion::Result res = questionOpen.askOpenOrSave(); 0044 qDebug() << res; 0045 if (res == BrowserOpenOrSaveQuestion::Open && questionOpen.selectedService()) { 0046 qDebug() << "Selected service:" << questionOpen.selectedService()->entryPath(); 0047 } 0048 } 0049 0050 return 0; 0051 }