diff --git a/core/smb4knotification.cpp b/core/smb4knotification.cpp index 178eb32..27975e9 100644 --- a/core/smb4knotification.cpp +++ b/core/smb4knotification.cpp @@ -1,480 +1,489 @@ /*************************************************************************** This class provides notifications for Smb4K. ------------------- begin : Son Jun 27 2010 copyright : (C) 2010-2019 by Alexander Reinholdt email : alexander.reinholdt@kdemail.net ***************************************************************************/ /*************************************************************************** * 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. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,* * MA 02110-1335, USA * ***************************************************************************/ #ifdef HAVE_CONFIG_H #include #endif // application specific includes #include "smb4knotification.h" #include "smb4knotification_p.h" #include "smb4ksettings.h" #include "smb4kbookmark.h" #include "smb4kworkgroup.h" #include "smb4khost.h" #include "smb4kshare.h" // KDE includes #define TRANSLATION_DOMAIN "smb4k-core" #include #include #include #include +#include "kiconthemes_version.h" using namespace KAuth; // // Notifications // void Smb4KNotification::shareMounted(const SharePtr &share) { Q_ASSERT(share); if (share) { QUrl mountpoint = QUrl::fromLocalFile(share->path()); Smb4KNotifier *notification = new Smb4KNotifier("shareMounted"); notification->setText(i18n("

The share %1 has been mounted to %2.

", share->displayString(), share->path())); +#if KICONTHEMES_VERSION < QT_VERSION_CHECK(5,52,0) notification->setPixmap(KIconLoader::global()->loadIcon("folder-network", KIconLoader::NoGroup, 0, KIconLoader::DefaultState, QStringList("emblem-mounted"))); +#else + notification->setPixmap(KIconLoader::global()->loadIcon("folder-network", KIconLoader::NoGroup, 0, KIconLoader::DefaultState, QStringList({"","emblem-mounted"}))); +#endif notification->setActions(QStringList(i18n("Open"))); notification->setMountpoint(mountpoint); notification->sendEvent(); } } void Smb4KNotification::shareUnmounted(const SharePtr &share) { Q_ASSERT(share); if (share) { Smb4KNotifier *notification = new Smb4KNotifier("shareUnmounted"); notification->setText(i18n("

The share %1 has been unmounted from %2.

", share->displayString(), share->path())); +#if KICONTHEMES_VERSION < QT_VERSION_CHECK(5,52,0) notification->setPixmap(KIconLoader::global()->loadIcon("folder-network", KIconLoader::NoGroup, 0, KIconLoader::DefaultState, QStringList("emblem-unmounted"))); +#else + notification->setPixmap(KIconLoader::global()->loadIcon("folder-network", KIconLoader::NoGroup, 0, KIconLoader::DefaultState, QStringList({"","emblem-unmounted"}))); +#endif notification->sendEvent(); } } void Smb4KNotification::sharesMounted(int number) { Smb4KNotifier *notification = new Smb4KNotifier("sharesMounted"); notification->setText(i18np("

%1 share has been mounted.

", "

%1 shares have been mounted.

", number)); notification->setPixmap(KIconLoader::global()->loadIcon("folder-network", KIconLoader::NoGroup, 0, KIconLoader::DefaultState, QStringList("emblem-mounted"))); notification->sendEvent(); } void Smb4KNotification::sharesUnmounted(int number) { Smb4KNotifier *notification = new Smb4KNotifier("sharesUnmounted"); notification->setText(i18np("

%1 share has been unmounted.

", "

%1 shares have been unmounted.

", number)); notification->setPixmap(KIconLoader::global()->loadIcon("folder-network", KIconLoader::NoGroup, 0, KIconLoader::DefaultState, QStringList("emblem-unmounted"))); notification->sendEvent(); } // // Warnings // void Smb4KNotification::openingWalletFailed(const QString& name) { Smb4KNotifier *notification = new Smb4KNotifier("openingWalletFailed"); notification->setText(i18n("

Opening the wallet %1 failed.

", name)); notification->setPixmap(KIconLoader::global()->loadIcon("dialog-warning", KIconLoader::NoGroup, 0, KIconLoader::DefaultState)); notification->sendEvent(); } void Smb4KNotification::credentialsNotAccessible() { Smb4KNotifier *notification = new Smb4KNotifier("credentialsNotAccessible"); notification->setText(i18n("

The credentials stored in the wallet could not be accessed. " "There is either no wallet available or it could not be opened.

")); notification->setPixmap(KIconLoader::global()->loadIcon("dialog-warning", KIconLoader::NoGroup, 0, KIconLoader::DefaultState)); notification->sendEvent(); } void Smb4KNotification::mimetypeNotSupported(const QString& mimetype) { Smb4KNotifier *notification = new Smb4KNotifier("mimetypeNotSupported"); notification->setText(i18n("

The mimetype %1 is not supported for printing. " "Please convert the file to PDF or Postscript and try again.

", mimetype)); notification->setPixmap(KIconLoader::global()->loadIcon("dialog-warning", KIconLoader::NoGroup, 0, KIconLoader::DefaultState)); notification->sendEvent(); } void Smb4KNotification::bookmarkExists(Smb4KBookmark* bookmark) { if (bookmark) { Smb4KNotifier *notification = new Smb4KNotifier("bookmarkExists"); notification->setText(i18n("

The bookmark for share %1 already exists and will be skipped.

", bookmark->displayString())); notification->setPixmap(KIconLoader::global()->loadIcon("dialog-warning", KIconLoader::NoGroup, 0, KIconLoader::DefaultState)); notification->sendEvent(); } } void Smb4KNotification::bookmarkLabelInUse(Smb4KBookmark* bookmark) { if (bookmark) { Smb4KNotifier *notification = new Smb4KNotifier("bookmarkLabelInUse"); notification->setText(i18n("

The label %1 of the bookmark for the share %2 " "is already being used and will automatically be renamed.

", bookmark->label(), bookmark->displayString())); notification->setPixmap(KIconLoader::global()->loadIcon("dialog-warning", KIconLoader::NoGroup, 0, KIconLoader::DefaultState)); notification->sendEvent(); } } void Smb4KNotification::sambaConfigFileMissing() { Smb4KNotifier *notification = new Smb4KNotifier("sambaConfigFileMissing"); notification->setText(i18n("The configuration file for the Samba suite smb.conf is missing. This is not " "a fatal error, but you should consider creating one.")); notification->setPixmap(KIconLoader::global()->loadIcon("dialog-warning", KIconLoader::NoGroup, 0, KIconLoader::DefaultState)); notification->sendEvent(); } // // Errors // void Smb4KNotification::mountingFailed(const SharePtr &share, const QString& err_msg) { if (share) { QString text; if (!err_msg.isEmpty()) { text = i18n("

Mounting the share %1 failed:

%2

", share->displayString(), err_msg); } else { text = i18n("

Mounting the share %1 failed.

", share->displayString()); } Smb4KNotifier *notification = new Smb4KNotifier("mountingFailed"); notification->setText(text); notification->setPixmap(KIconLoader::global()->loadIcon("dialog-error", KIconLoader::NoGroup, 0, KIconLoader::DefaultState)); notification->sendEvent(); } } void Smb4KNotification::unmountingFailed(const SharePtr &share, const QString& err_msg) { if (share) { QString text; if (!err_msg.isEmpty()) { text = i18n("

Unmounting the share %1 from %2 failed:

%3

", share->displayString(), share->path(), err_msg); } else { text = i18n("

Unmounting the share %1 from %2 failed.

", share->displayString(), share->path()); } Smb4KNotifier *notification = new Smb4KNotifier("unmountingFailed"); notification->setText(text); notification->setPixmap(KIconLoader::global()->loadIcon("dialog-error", KIconLoader::NoGroup, 0, KIconLoader::DefaultState)); notification->sendEvent(); } } void Smb4KNotification::unmountingNotAllowed(const SharePtr &share) { Q_ASSERT(share); if (share) { Smb4KNotifier *notification = new Smb4KNotifier("unmountingNotAllowed"); notification->setText(i18n("

You are not allowed to unmount the share %1 from %2. " "It is owned by the user %3.

", share->displayString(), share->path(), share->user().loginName())); notification->setPixmap(KIconLoader::global()->loadIcon("dialog-error", KIconLoader::NoGroup, 0, KIconLoader::DefaultState)); notification->sendEvent(); } } void Smb4KNotification::synchronizationFailed(const QUrl& src, const QUrl& dest, const QString& err_msg) { QString text; if (!err_msg.isEmpty()) { text = i18n("

Synchronizing %1 with %2 failed:

%3

", dest.path(), src.path(), err_msg); } else { text = i18n("

Synchronizing %1 with %2 failed.

", dest.path(), src.path()); } Smb4KNotifier *notification = new Smb4KNotifier("synchronizationFailed"); notification->setText(text); notification->setPixmap(KIconLoader::global()->loadIcon("dialog-error", KIconLoader::NoGroup, 0, KIconLoader::DefaultState)); notification->sendEvent(); } void Smb4KNotification::commandNotFound(const QString& command) { Smb4KNotifier *notification = new Smb4KNotifier("commandNotFound"); notification->setText(i18n("

The command %1 could not be found. Please check your installation.

", command)); notification->setPixmap(KIconLoader::global()->loadIcon("dialog-error", KIconLoader::NoGroup, 0, KIconLoader::DefaultState)); notification->sendEvent(); } void Smb4KNotification::cannotBookmarkPrinter(const SharePtr &share) { if (share && share->isPrinter()) { Smb4KNotifier *notification = new Smb4KNotifier("cannotBookmarkPrinter"); notification->setText(i18n("

The share %1 is a printer and cannot be bookmarked.

", share->displayString())); notification->setPixmap(KIconLoader::global()->loadIcon("dialog-error", KIconLoader::NoGroup, 0, KIconLoader::DefaultState)); notification->sendEvent(); } } void Smb4KNotification::fileNotFound(const QString& fileName) { Smb4KNotifier *notification = new Smb4KNotifier("fileNotFound"); notification->setText(i18n("

The file %1 could not be found.

", fileName)); notification->setPixmap(KIconLoader::global()->loadIcon("dialog-error", KIconLoader::NoGroup, 0, KIconLoader::DefaultState)); notification->sendEvent(); } void Smb4KNotification::openingFileFailed(const QFile& file) { QString text; if (!file.errorString().isEmpty()) { text = i18n("

Opening the file %1 failed:

%2

", file.fileName(), file.errorString()); } else { text = i18n("

Opening the file %1 failed.

", file.fileName()); } Smb4KNotifier *notification = new Smb4KNotifier("openingFileFailed"); notification->setText(text); notification->setPixmap(KIconLoader::global()->loadIcon("dialog-error", KIconLoader::NoGroup, 0, KIconLoader::DefaultState)); notification->sendEvent(); } void Smb4KNotification::readingFileFailed(const QFile& file, const QString& err_msg) { QString text; if (!err_msg.isEmpty()) { text = i18n("

Reading from file %1 failed:

%2

", file.fileName(), err_msg); } else { if (!file.errorString().isEmpty()) { text = i18n("

Reading from file %1 failed:

%2

", file.fileName(), file.errorString()); } else { text = i18n("

Reading from file %1 failed.

", file.fileName()); } } Smb4KNotifier *notification = new Smb4KNotifier("readingFileFailed"); notification->setText(text); notification->setPixmap(KIconLoader::global()->loadIcon("dialog-error", KIconLoader::NoGroup, 0, KIconLoader::DefaultState)); notification->sendEvent(); } void Smb4KNotification::mkdirFailed(const QDir& dir) { Smb4KNotifier *notification = new Smb4KNotifier("mkdirFailed"); notification->setText(i18n("

The following directory could not be created:

%1

", dir.absolutePath())); notification->setPixmap(KIconLoader::global()->loadIcon("dialog-error", KIconLoader::NoGroup, 0, KIconLoader::DefaultState)); notification->sendEvent(); } void Smb4KNotification::processError(QProcess::ProcessError error) { QString text; switch (error) { case QProcess::FailedToStart: { text = i18n("

The process failed to start (error code: %1).

", error); break; } case QProcess::Crashed: { text = i18n("

The process crashed (error code: %1).

", error); break; } case QProcess::Timedout: { text = i18n("

The process timed out (error code: %1).

", error); break; } case QProcess::WriteError: { text = i18n("

Could not write to the process (error code: %1).

", error); break; } case QProcess::ReadError: { text = i18n("

Could not read from the process (error code: %1).

", error); break; } case QProcess::UnknownError: default: { text = i18n("

The process reported an unknown error.

"); break; } } Smb4KNotifier *notification = new Smb4KNotifier("processError"); notification->setText(text); notification->setPixmap(KIconLoader::global()->loadIcon("dialog-error", KIconLoader::NoGroup, 0, KIconLoader::DefaultState)); notification->sendEvent(); } void Smb4KNotification::actionFailed(int err_code) { QString text, err_msg; switch (err_code) { case ActionReply::NoResponderError: { err_msg = "NoResponderError"; break; } case ActionReply::NoSuchActionError: { err_msg = "NoSuchActionError"; break; } case ActionReply::InvalidActionError: { err_msg = "InvalidActionError"; break; } case ActionReply::AuthorizationDeniedError: { err_msg = "AuthorizationDeniedError"; break; } case ActionReply::UserCancelledError: { err_msg = "UserCancelledError"; break; } case ActionReply::HelperBusyError: { err_msg = "HelperBusyError"; break; } case ActionReply::AlreadyStartedError: { err_msg = "AlreadyStartedError"; break; } case ActionReply::DBusError: { err_msg = "DBusError"; break; } case ActionReply::BackendError: { err_msg = "BackendError"; break; } default: { break; } } if (!err_msg.isEmpty()) { text = i18n("

Executing an action with root privileges failed (error code: %1).

", err_msg); } else { text = i18n("

Executing an action with root privileges failed.

"); } Smb4KNotifier *notification = new Smb4KNotifier("actionFailed"); notification->setText(text); notification->setPixmap(KIconLoader::global()->loadIcon("dialog-error", KIconLoader::NoGroup, 0, KIconLoader::DefaultState)); notification->sendEvent(); } void Smb4KNotification::invalidURLPassed() { Smb4KNotifier *notification = new Smb4KNotifier("invalidURL"); notification->setText(i18n("

The URL that was passed is invalid.

")); notification->setPixmap(KIconLoader::global()->loadIcon("dialog-error", KIconLoader::NoGroup, 0, KIconLoader::DefaultState)); notification->sendEvent(); } void Smb4KNotification::networkCommunicationFailed(const QString& errorMessage) { Smb4KNotifier *notification = new Smb4KNotifier("networkCommunicationFailed"); notification->setText(i18n("The network communication failed with the following error message: %1", errorMessage)); notification->setPixmap(KIconLoader::global()->loadIcon("dialog-error", KIconLoader::NoGroup, 0, KIconLoader::DefaultState)); notification->sendEvent(); }