Commit 9307eb0f authored by Michal Malý's avatar Michal Malý Committed by Elvis Angelaccio

Make error strings in a separate method

Summary: Decouple the strings returned as error messages from the reportError() method.

Reviewers: elvisangelaccio

Reviewed By: elvisangelaccio

Differential Revision: https://phabricator.kde.org/D6731
parent 75426495
......@@ -94,6 +94,12 @@ class SMBSlave : public QObject, public KIO::SlaveBase
Q_OBJECT
private:
class SMBError {
public:
int kioErrorId;
QString errorString;
};
//---------------------------------------------------------------------
// please make sure your private data does not duplicate existing data
//---------------------------------------------------------------------
......@@ -211,7 +217,7 @@ protected:
*/
QUrl checkURL(const QUrl& kurl) const;
void reportError(const SMBUrl &kurl, const int &errNum);
void reportError(const SMBUrl& url, const int errNum);
void reportWarning(const SMBUrl& url, const int errNum);
public:
......@@ -268,6 +274,7 @@ protected:
void virtual_hook(int id, void *data) Q_DECL_OVERRIDE;
private:
SMBError errnumToKioError(const SMBUrl& url, const int errNum);
void smbCopy(const QUrl& src, const QUrl &dest, int permissions, KIO::JobFlags flags);
void smbCopyGet(const QUrl& src, const QUrl& dest, int permissions, KIO::JobFlags flags);
void smbCopyPut(const QUrl& src, const QUrl& dest, int permissions, KIO::JobFlags flags);
......
......@@ -213,7 +213,7 @@ QUrl SMBSlave::checkURL(const QUrl& kurl) const
return url;
}
void SMBSlave::reportError(const SMBUrl &url, const int &errNum)
SMBSlave::SMBError SMBSlave::errnumToKioError(const SMBUrl &url, const int errNum)
{
qCDebug(KIO_SMB) << "errNum" << errNum;
......@@ -221,78 +221,73 @@ void SMBSlave::reportError(const SMBUrl &url, const int &errNum)
{
case ENOENT:
if (url.getType() == SMBURLTYPE_ENTIRE_NETWORK)
error( ERR_SLAVE_DEFINED, i18n("Unable to find any workgroups in your local network. This might be caused by an enabled firewall."));
return SMBError{ ERR_SLAVE_DEFINED, i18n("Unable to find any workgroups in your local network. This might be caused by an enabled firewall.") };
else
error( ERR_DOES_NOT_EXIST, url.toDisplayString());
break;
return SMBError{ ERR_DOES_NOT_EXIST, url.toDisplayString() };
#ifdef ENOMEDIUM
case ENOMEDIUM:
error( ERR_SLAVE_DEFINED,
i18n( "No media in device for %1", url.toDisplayString() ) );
break;
return SMBError{ ERR_SLAVE_DEFINED, i18n("No media in device for %1", url.toDisplayString()) };
#endif
#ifdef EHOSTDOWN
case EHOSTDOWN:
#endif
case ECONNREFUSED:
error( ERR_SLAVE_DEFINED,
i18n( "Could not connect to host for %1", url.toDisplayString() ) );
return SMBError{ ERR_SLAVE_DEFINED, i18n("Could not connect to host for %1", url.toDisplayString()) };
break;
case ENOTDIR:
error( ERR_CANNOT_ENTER_DIRECTORY, url.toDisplayString());
break;
return SMBError{ ERR_CANNOT_ENTER_DIRECTORY, url.toDisplayString() };
case EFAULT:
case EINVAL:
error( ERR_DOES_NOT_EXIST, url.toDisplayString());
break;
return SMBError{ ERR_DOES_NOT_EXIST, url.toDisplayString() };
case EPERM:
case EACCES:
error( ERR_ACCESS_DENIED, url.toDisplayString() );
break;
return SMBError{ ERR_ACCESS_DENIED, url.toDisplayString() };
case EIO:
case ENETUNREACH:
if ( url.getType() == SMBURLTYPE_ENTIRE_NETWORK || url.getType() == SMBURLTYPE_WORKGROUP_OR_SERVER )
error( ERR_SLAVE_DEFINED, i18n( "Error while connecting to server responsible for %1", url.toDisplayString() ) );
return SMBError{ ERR_SLAVE_DEFINED, i18n("Error while connecting to server responsible for %1", url.toDisplayString()) };
else
error( ERR_CONNECTION_BROKEN, url.toDisplayString());
break;
return SMBError{ ERR_CONNECTION_BROKEN, url.toDisplayString() };
case ENOMEM:
error( ERR_OUT_OF_MEMORY, url.toDisplayString() );
break;
return SMBError{ ERR_OUT_OF_MEMORY, url.toDisplayString() };
case ENODEV:
error( ERR_SLAVE_DEFINED, i18n("Share could not be found on given server"));
break;
return SMBError{ ERR_SLAVE_DEFINED, i18n("Share could not be found on given server") };
case EBADF:
error( ERR_INTERNAL, i18n("BAD File descriptor"));
break;
return SMBError{ ERR_INTERNAL, i18n("Bad file descriptor") };
case ETIMEDOUT:
error( ERR_SERVER_TIMEOUT, url.host() );
break;
return SMBError{ ERR_SERVER_TIMEOUT, url.host() };
#ifdef ENOTUNIQ
case ENOTUNIQ:
error( ERR_SLAVE_DEFINED, i18n( "The given name could not be resolved to a unique server. "
"Make sure your network is setup without any name conflicts "
"between names used by Windows and by UNIX name resolution." ) );
break;
return SMBError{ ERR_SLAVE_DEFINED, i18n("The given name could not be resolved to a unique server. "
"Make sure your network is setup without any name conflicts "
"between names used by Windows and by UNIX name resolution." ) };
#endif
case 0: // success
error( ERR_INTERNAL, i18n("libsmbclient reported an error, but did not specify "
"what the problem is. This might indicate a severe problem "
"with your network - but also might indicate a problem with "
"libsmbclient.\n"
"If you want to help us, please provide a tcpdump of the "
"network interface while you try to browse (be aware that "
"it might contain private data, so do not post it if you are "
"unsure about that - you can send it privately to the developers "
"if they ask for it)") );
break;
return SMBError{ ERR_INTERNAL, i18n("libsmbclient reported an error, but did not specify "
"what the problem is. This might indicate a severe problem "
"with your network - but also might indicate a problem with "
"libsmbclient.\n"
"If you want to help us, please provide a tcpdump of the "
"network interface while you try to browse (be aware that "
"it might contain private data, so do not post it if you are "
"unsure about that - you can send it privately to the developers "
"if they ask for it)") };
default:
error( ERR_INTERNAL, i18n("Unknown error condition in stat: %1", QString::fromLocal8Bit( strerror(errNum))) );
return SMBError{ ERR_INTERNAL, i18n("Unknown error condition in stat: %1", QString::fromLocal8Bit( strerror(errNum))) };
}
}
void SMBSlave::reportError(const SMBUrl& url, const int errNum)
{
const SMBError smbErr = errnumToKioError(url, errNum);
error(smbErr.kioErrorId, smbErr.errorString);
}
void SMBSlave::reportWarning(const SMBUrl& url, const int errNum)
{
const SMBError smbErr = errnumToKioError(url, errNum);
warning(i18n("Error %1 while browsing: %2", errNum, url.url()));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment