The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
3.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. bool FileChooser::isPlatformDialogAvailable()
  19. {
  20. ChildProcess child;
  21. const bool ok = child.start ("which zenity")
  22. && child.readAllProcessOutput().trim().isNotEmpty();
  23. child.waitForProcessToFinish (60 * 1000);
  24. return ok;
  25. }
  26. void FileChooser::showPlatformDialog (Array<File>& results,
  27. const String& title,
  28. const File& file,
  29. const String& filters,
  30. bool isDirectory,
  31. bool selectsFiles,
  32. bool isSave,
  33. bool warnAboutOverwritingExistingFiles,
  34. bool selectMultipleFiles,
  35. FilePreviewComponent* previewComponent)
  36. {
  37. const String separator (":");
  38. String command ("zenity --file-selection");
  39. if (title.isNotEmpty()) command << " --title=\"" << title << "\"";
  40. if (file != File::nonexistent) command << " --filename=\"" << file.getFullPathName () << "\"";
  41. if (isDirectory) command << " --directory";
  42. if (isSave) command << " --save";
  43. if (selectMultipleFiles) command << " --multiple --separator=" << separator;
  44. command << " 2>&1";
  45. ChildProcess child;
  46. if (child.start (command))
  47. {
  48. const String result (child.readAllProcessOutput().trim());
  49. if (result.isNotEmpty())
  50. {
  51. StringArray tokens;
  52. if (selectMultipleFiles)
  53. tokens.addTokens (result, separator, "\"");
  54. else
  55. tokens.add (result);
  56. for (int i = 0; i < tokens.size(); i++)
  57. results.add (File (tokens[i]));
  58. }
  59. child.waitForProcessToFinish (60 * 1000);
  60. }
  61. }