PageRenderTime 60ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/Qt/ApplicationComponents/pqDesktopServicesReaction.cxx

https://github.com/Kitware/ParaView
C++ | 78 lines | 38 code | 5 blank | 35 comment | 4 complexity | cfe1775858f42d255f2244aa7b502c0c MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0
  1. /*=========================================================================
  2. Program: ParaView
  3. Module: pqDesktopServicesReaction.cxx
  4. Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
  5. All rights reserved.
  6. ParaView is a free software; you can redistribute it and/or modify it
  7. under the terms of the ParaView license version 1.2.
  8. See License_v1.2.txt for the full ParaView license.
  9. A copy of this license can be obtained by contacting
  10. Kitware Inc.
  11. 28 Corporate Drive
  12. Clifton Park, NY 12065
  13. USA
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  16. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
  18. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. ========================================================================*/
  26. #include "pqDesktopServicesReaction.h"
  27. #include "pqCoreUtilities.h"
  28. #include <QDesktopServices>
  29. #include <QFileInfo>
  30. #include <QMessageBox>
  31. #include <QtDebug>
  32. #include <iostream>
  33. //-----------------------------------------------------------------------------
  34. pqDesktopServicesReaction::pqDesktopServicesReaction(const QUrl& url, QAction* parentObject)
  35. : Superclass(parentObject)
  36. , URL(url)
  37. {
  38. if (parentObject)
  39. {
  40. parentObject->setStatusTip(url.toString());
  41. }
  42. }
  43. //-----------------------------------------------------------------------------
  44. pqDesktopServicesReaction::~pqDesktopServicesReaction() = default;
  45. //-----------------------------------------------------------------------------
  46. bool pqDesktopServicesReaction::openUrl(const QUrl& url)
  47. {
  48. if (url.isLocalFile() && !QFileInfo(url.toLocalFile()).exists())
  49. {
  50. QString filename = QFileInfo(url.toLocalFile()).absoluteFilePath();
  51. QString msg =
  52. QString("The requested file is not available in your installation. "
  53. "You can manually obtain and place the file (or ask your administrators) at the "
  54. "following location for this to work.\n\n'%1'")
  55. .arg(filename);
  56. // dump to cout for easy copy/paste.
  57. std::cout << msg.toUtf8().data() << std::endl;
  58. QMessageBox::warning(pqCoreUtilities::mainWidget(), "Missing file", msg, QMessageBox::Ok);
  59. return false;
  60. }
  61. if (!QDesktopServices::openUrl(url))
  62. {
  63. qCritical() << "Failed to open '" << url << "'";
  64. return false;
  65. }
  66. return true;
  67. }