2017-05-10 10:37:10 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Christian Kamm <mail@ckamm.de>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "guiutility.h"
|
|
|
|
|
|
|
|
#include <QClipboard>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QDesktopServices>
|
2017-07-04 17:41:40 +03:00
|
|
|
#include <QLoggingCategory>
|
2017-05-10 10:37:10 +03:00
|
|
|
#include <QMessageBox>
|
2017-12-08 12:10:28 +03:00
|
|
|
#include <QUrlQuery>
|
2017-05-10 10:37:10 +03:00
|
|
|
|
2019-04-16 10:47:55 +03:00
|
|
|
#include "common/asserts.h"
|
|
|
|
|
2017-05-10 10:37:10 +03:00
|
|
|
using namespace OCC;
|
|
|
|
|
2017-12-28 22:33:10 +03:00
|
|
|
Q_LOGGING_CATEGORY(lcUtility, "nextcloud.gui.utility", QtInfoMsg)
|
2017-07-04 17:41:40 +03:00
|
|
|
|
2017-05-10 10:37:10 +03:00
|
|
|
bool Utility::openBrowser(const QUrl &url, QWidget *errorWidgetParent)
|
|
|
|
{
|
2017-07-04 17:41:40 +03:00
|
|
|
if (!QDesktopServices::openUrl(url)) {
|
|
|
|
if (errorWidgetParent) {
|
|
|
|
QMessageBox::warning(
|
|
|
|
errorWidgetParent,
|
|
|
|
QCoreApplication::translate("utility", "Could not open browser"),
|
|
|
|
QCoreApplication::translate("utility",
|
|
|
|
"There was an error when launching the browser to go to "
|
|
|
|
"URL %1. Maybe no default browser is configured?")
|
|
|
|
.arg(url.toString()));
|
|
|
|
}
|
|
|
|
qCWarning(lcUtility) << "QDesktopServices::openUrl failed for" << url;
|
2017-05-10 10:37:10 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Utility::openEmailComposer(const QString &subject, const QString &body, QWidget *errorWidgetParent)
|
|
|
|
{
|
2017-07-04 17:43:17 +03:00
|
|
|
QUrl url(QLatin1String("mailto:"));
|
2017-12-08 12:10:28 +03:00
|
|
|
QUrlQuery query;
|
|
|
|
query.setQueryItems({ { QLatin1String("subject"), subject },
|
2017-05-10 10:37:10 +03:00
|
|
|
{ QLatin1String("body"), body } });
|
2017-12-08 12:10:28 +03:00
|
|
|
url.setQuery(query);
|
2017-05-10 10:37:10 +03:00
|
|
|
|
2017-07-04 17:41:40 +03:00
|
|
|
if (!QDesktopServices::openUrl(url)) {
|
|
|
|
if (errorWidgetParent) {
|
|
|
|
QMessageBox::warning(
|
|
|
|
errorWidgetParent,
|
|
|
|
QCoreApplication::translate("utility", "Could not open email client"),
|
|
|
|
QCoreApplication::translate("utility",
|
|
|
|
"There was an error when launching the email client to "
|
|
|
|
"create a new message. Maybe no default email client is "
|
|
|
|
"configured?"));
|
|
|
|
}
|
|
|
|
qCWarning(lcUtility) << "QDesktopServices::openUrl failed for" << url;
|
2017-05-10 10:37:10 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-16 10:47:55 +03:00
|
|
|
|
|
|
|
QString Utility::vfsCurrentAvailabilityText(VfsItemAvailability availability, bool forFolder)
|
|
|
|
{
|
|
|
|
switch(availability) {
|
|
|
|
case VfsItemAvailability::AlwaysLocal:
|
|
|
|
return QCoreApplication::translate("utility", "Currently always available locally");
|
|
|
|
case VfsItemAvailability::AllHydrated:
|
|
|
|
return QCoreApplication::translate("utility", "Currently available locally");
|
|
|
|
case VfsItemAvailability::SomeDehydrated:
|
|
|
|
if (forFolder) {
|
|
|
|
return QCoreApplication::translate("utility", "Currently some available online only");
|
|
|
|
} else {
|
|
|
|
return QCoreApplication::translate("utility", "Currently available online only");
|
|
|
|
}
|
|
|
|
case VfsItemAvailability::OnlineOnly:
|
|
|
|
return QCoreApplication::translate("utility", "Currently available online only");
|
|
|
|
}
|
|
|
|
ENFORCE(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Utility::vfsPinActionText()
|
|
|
|
{
|
|
|
|
return QCoreApplication::translate("utility", "Make always available locally");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Utility::vfsFreeSpaceActionText()
|
|
|
|
{
|
|
|
|
return QCoreApplication::translate("utility", "Free up local space");
|
|
|
|
}
|