Changeset View
Changeset View
Standalone View
Standalone View
src/kdialog.cpp
Show First 20 Lines • Show All 248 Lines • ▼ Show 20 Line(s) | |||||
249 | static QUrl initialDirectory(const QUrl &url) | 249 | static QUrl initialDirectory(const QUrl &url) | ||
250 | { | 250 | { | ||
251 | if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) { | 251 | if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) { | ||
252 | return url; | 252 | return url; | ||
253 | } | 253 | } | ||
254 | return url.adjusted(QUrl::RemoveFilename); | 254 | return url.adjusted(QUrl::RemoveFilename); | ||
255 | } | 255 | } | ||
256 | 256 | | |||
257 | static QStringList schemesthatReturnLocalFiles() | ||||
258 | { | ||||
259 | return { | ||||
260 | QStringLiteral("desktop") | ||||
261 | , QStringLiteral("file") | ||||
262 | , QStringLiteral("recentlyused") | ||||
263 | , QStringLiteral("trash") | ||||
264 | , QStringLiteral("tags") | ||||
265 | // TODO: whatever provides removable devices | ||||
266 | }; | ||||
267 | } | ||||
268 | | ||||
257 | int main(int argc, char *argv[]) | 269 | int main(int argc, char *argv[]) | ||
258 | { | 270 | { | ||
259 | // Bug 373677: Qt removes various arguments it treats internally (such as title and icon) from args | 271 | // Bug 373677: Qt removes various arguments it treats internally (such as title and icon) from args | ||
260 | // and applies them to the first Qt::Window, while here we only show dialogs | 272 | // and applies them to the first Qt::Window, while here we only show dialogs | ||
261 | // so we need to store them before we even create our QApplication | 273 | // so we need to store them before we even create our QApplication | ||
262 | QStringList rawArgs; | 274 | QStringList rawArgs; | ||
263 | for (int i = 0; i < argc; ++i) { | 275 | for (int i = 0; i < argc; ++i) { | ||
264 | rawArgs << QString::fromLocal8Bit(argv[i]); | 276 | rawArgs << QString::fromLocal8Bit(argv[i]); | ||
▲ Show 20 Lines • Show All 527 Lines • ▼ Show 20 Line(s) | 791 | if (parser.isSet(QStringLiteral("getopenfilename")) || parser.isSet(QStringLiteral("getopenurl"))) { | |||
792 | 804 | | |||
793 | if (multiple) { | 805 | if (multiple) { | ||
794 | dlg.setFileMode(QFileDialog::ExistingFiles); | 806 | dlg.setFileMode(QFileDialog::ExistingFiles); | ||
795 | } else { | 807 | } else { | ||
796 | dlg.setFileMode(QFileDialog::ExistingFile); | 808 | dlg.setFileMode(QFileDialog::ExistingFile); | ||
797 | } | 809 | } | ||
798 | const bool openUrls = parser.isSet(QStringLiteral("getopenurl")); | 810 | const bool openUrls = parser.isSet(QStringLiteral("getopenurl")); | ||
799 | if (!openUrls) { | 811 | if (!openUrls) { | ||
800 | dlg.setSupportedSchemes({QStringLiteral("file")}); | 812 | dlg.setSupportedSchemes(schemesthatReturnLocalFiles()); | ||
801 | } | 813 | } | ||
802 | setFileDialogFilter(dlg, filter); | 814 | setFileDialogFilter(dlg, filter); | ||
803 | Utils::handleXGeometry(&dlg); | 815 | Utils::handleXGeometry(&dlg); | ||
804 | dlg.setWindowTitle(title.isEmpty() ? i18nc("@title:window", "Open") : title); | 816 | dlg.setWindowTitle(title.isEmpty() ? i18nc("@title:window", "Open") : title); | ||
805 | if (!dlg.exec()) { | 817 | if (!dlg.exec()) { | ||
806 | return 1; // canceled | 818 | return 1; // canceled | ||
807 | } | 819 | } | ||
808 | 820 | | |||
Show All 36 Lines | 849 | if ((parser.isSet(QStringLiteral("getsavefilename"))) || (parser.isSet(QStringLiteral("getsaveurl")))) { | |||
845 | QFileDialog dlg; | 857 | QFileDialog dlg; | ||
846 | dlg.setAcceptMode(QFileDialog::AcceptSave); | 858 | dlg.setAcceptMode(QFileDialog::AcceptSave); | ||
847 | dlg.setFileMode(QFileDialog::AnyFile); | 859 | dlg.setFileMode(QFileDialog::AnyFile); | ||
848 | dlg.setDirectoryUrl(initialDirectory(startUrl)); | 860 | dlg.setDirectoryUrl(initialDirectory(startUrl)); | ||
849 | dlg.selectFile(initialSelection(startUrl)); | 861 | dlg.selectFile(initialSelection(startUrl)); | ||
850 | setFileDialogFilter(dlg, filter); | 862 | setFileDialogFilter(dlg, filter); | ||
851 | const bool saveUrls = parser.isSet(QStringLiteral("getsaveurl")); | 863 | const bool saveUrls = parser.isSet(QStringLiteral("getsaveurl")); | ||
852 | if (!saveUrls) { | 864 | if (!saveUrls) { | ||
853 | dlg.setSupportedSchemes({QStringLiteral("file")}); | 865 | dlg.setSupportedSchemes(schemesthatReturnLocalFiles()); | ||
meven: The trash recentlyused tags and desktop ioslaves can't be save filename' folder since they are… | |||||
kdialog can be used to show open dialogs as well as save dialogs, where writability is not an issue. Also, the default dialog will show these ioslaves and let you try to write into them, so I believe if we want to do that, they should be filtered out there in the KIO places model, rather than here. ngraham: `kdialog` can be used to show open dialogs as well as save dialogs, where writability is not an… | |||||
854 | } | 866 | } | ||
855 | Utils::handleXGeometry(&dlg); | 867 | Utils::handleXGeometry(&dlg); | ||
856 | dlg.setWindowTitle(title.isEmpty() ? i18nc("@title:window", "Save As") : title); | 868 | dlg.setWindowTitle(title.isEmpty() ? i18nc("@title:window", "Save As") : title); | ||
857 | if (!dlg.exec()) { | 869 | if (!dlg.exec()) { | ||
858 | return 1; // canceled | 870 | return 1; // canceled | ||
859 | } | 871 | } | ||
860 | 872 | | |||
861 | if (saveUrls) { | 873 | if (saveUrls) { | ||
▲ Show 20 Lines • Show All 219 Lines • Show Last 20 Lines |
The trash recentlyused tags and desktop ioslaves can't be save filename' folder since they are not writable.
So I believe this should be undone here.