/src/gui/guiutility.cpp

https://github.com/nextcloud/desktop · C++ · 68 lines · 48 code · 7 blank · 13 comment · 4 complexity · 6d744b7154b96fd1d8df0e27967ed0de MD5 · raw file

  1. /*
  2. * Copyright (C) by Christian Kamm <mail@ckamm.de>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. */
  14. #include "guiutility.h"
  15. #include <QClipboard>
  16. #include <QApplication>
  17. #include <QDesktopServices>
  18. #include <QLoggingCategory>
  19. #include <QMessageBox>
  20. #include <QUrlQuery>
  21. using namespace OCC;
  22. Q_LOGGING_CATEGORY(lcUtility, "nextcloud.gui.utility", QtInfoMsg)
  23. bool Utility::openBrowser(const QUrl &url, QWidget *errorWidgetParent)
  24. {
  25. if (!QDesktopServices::openUrl(url)) {
  26. if (errorWidgetParent) {
  27. QMessageBox::warning(
  28. errorWidgetParent,
  29. QCoreApplication::translate("utility", "Could not open browser"),
  30. QCoreApplication::translate("utility",
  31. "There was an error when launching the browser to go to "
  32. "URL %1. Maybe no default browser is configured?")
  33. .arg(url.toString()));
  34. }
  35. qCWarning(lcUtility) << "QDesktopServices::openUrl failed for" << url;
  36. return false;
  37. }
  38. return true;
  39. }
  40. bool Utility::openEmailComposer(const QString &subject, const QString &body, QWidget *errorWidgetParent)
  41. {
  42. QUrl url(QLatin1String("mailto:"));
  43. QUrlQuery query;
  44. query.setQueryItems({ { QLatin1String("subject"), subject },
  45. { QLatin1String("body"), body } });
  46. url.setQuery(query);
  47. if (!QDesktopServices::openUrl(url)) {
  48. if (errorWidgetParent) {
  49. QMessageBox::warning(
  50. errorWidgetParent,
  51. QCoreApplication::translate("utility", "Could not open email client"),
  52. QCoreApplication::translate("utility",
  53. "There was an error when launching the email client to "
  54. "create a new message. Maybe no default email client is "
  55. "configured?"));
  56. }
  57. qCWarning(lcUtility) << "QDesktopServices::openUrl failed for" << url;
  58. return false;
  59. }
  60. return true;
  61. }