mirror of
https://github.com/transmission/transmission
synced 2024-12-22 07:42:37 +00:00
refactor: inline simple getters in qt client (#6621)
* refactor: make RpcClient::url() constexpr * refactor: make Session::getRemoteUrl() constexpr * refactor: make RpcQueue::setTolerateErrors() constexpr * refactor: make RpcClient::isLocal() constexpr * refactor: make Session::isLocal() constexpr * refactor: make Session::isServer() constexpr * refactor: make PathButton::label() constexpr * chore: remove accidentally-committed makelog file
This commit is contained in:
parent
b1b685af3f
commit
a90d0fce2b
8 changed files with 28 additions and 52 deletions
|
@ -1 +0,0 @@
|
|||
ninja: error: loading 'build.ninja': No such file or directory
|
|
@ -63,11 +63,6 @@ void PathButton::setPath(QString const& path)
|
|||
emit pathChanged(path_);
|
||||
}
|
||||
|
||||
QString const& PathButton::path() const
|
||||
{
|
||||
return path_;
|
||||
}
|
||||
|
||||
QSize PathButton::sizeHint() const
|
||||
{
|
||||
auto const sh = QToolButton::sizeHint();
|
||||
|
|
|
@ -28,7 +28,11 @@ public:
|
|||
void setNameFilter(QString const& name_filter);
|
||||
|
||||
void setPath(QString const& path);
|
||||
QString const& path() const;
|
||||
|
||||
[[nodiscard]] constexpr auto const& path() const noexcept
|
||||
{
|
||||
return path_;
|
||||
}
|
||||
|
||||
// QWidget
|
||||
QSize sizeHint() const override;
|
||||
|
|
|
@ -67,29 +67,10 @@ void RpcClient::start(tr_session* session)
|
|||
void RpcClient::start(QUrl const& url)
|
||||
{
|
||||
url_ = url;
|
||||
url_is_loopback_ = QHostAddress{ url_.host() }.isLoopback();
|
||||
request_.reset();
|
||||
}
|
||||
|
||||
bool RpcClient::isLocal() const
|
||||
{
|
||||
if (session_ != nullptr)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (QHostAddress{ url_.host() }.isLoopback())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QUrl const& RpcClient::url() const
|
||||
{
|
||||
return url_;
|
||||
}
|
||||
|
||||
RpcResponseFuture RpcClient::exec(tr_quark method, tr_variant* args)
|
||||
{
|
||||
return exec(tr_quark_get_string_view(method), args);
|
||||
|
|
|
@ -55,13 +55,20 @@ class RpcClient : public QObject
|
|||
public:
|
||||
explicit RpcClient(QObject* parent = nullptr);
|
||||
|
||||
[[nodiscard]] constexpr auto const& url() const noexcept
|
||||
{
|
||||
return url_;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto isLocal() const noexcept
|
||||
{
|
||||
return session_ != nullptr || url_is_loopback_;
|
||||
}
|
||||
|
||||
void stop();
|
||||
void start(tr_session* session);
|
||||
void start(QUrl const& url);
|
||||
|
||||
bool isLocal() const;
|
||||
QUrl const& url() const;
|
||||
|
||||
RpcResponseFuture exec(tr_quark method, tr_variant* args);
|
||||
RpcResponseFuture exec(std::string_view method, tr_variant* args);
|
||||
|
||||
|
@ -94,4 +101,5 @@ private:
|
|||
std::unordered_map<int64_t, QFutureInterface<RpcResponse>> local_requests_;
|
||||
int64_t next_tag_ = {};
|
||||
bool const verbose_ = qEnvironmentVariableIsSet("TR_RPC_VERBOSE");
|
||||
bool url_is_loopback_ = false;
|
||||
};
|
||||
|
|
|
@ -27,7 +27,7 @@ class RpcQueue : public QObject
|
|||
public:
|
||||
explicit RpcQueue(QObject* parent = nullptr);
|
||||
|
||||
void setTolerateErrors(bool tolerate_errors = true)
|
||||
constexpr void setTolerateErrors(bool tolerate_errors = true)
|
||||
{
|
||||
tolerate_errors_ = tolerate_errors;
|
||||
}
|
||||
|
|
|
@ -386,24 +386,7 @@ void Session::start()
|
|||
emit sourceChanged();
|
||||
}
|
||||
|
||||
bool Session::isServer() const
|
||||
{
|
||||
return session_ != nullptr;
|
||||
}
|
||||
|
||||
bool Session::isLocal() const
|
||||
{
|
||||
if (!session_id_.isEmpty())
|
||||
{
|
||||
return is_definitely_local_session_;
|
||||
}
|
||||
|
||||
return rpc_.isLocal();
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
// ---
|
||||
|
||||
void Session::addOptionalIds(tr_variant* args_dict, torrent_ids_t const& torrent_ids) const
|
||||
{
|
||||
|
|
12
qt/Session.h
12
qt/Session.h
|
@ -46,7 +46,7 @@ public:
|
|||
void stop();
|
||||
void restart();
|
||||
|
||||
QUrl const& getRemoteUrl() const
|
||||
[[nodiscard]] constexpr auto const& getRemoteUrl() const noexcept
|
||||
{
|
||||
return rpc_.url();
|
||||
}
|
||||
|
@ -86,10 +86,16 @@ public:
|
|||
bool portTestPending(PortTestIpProtocol ip_protocol) const noexcept;
|
||||
|
||||
/** returns true if the transmission session is being run inside this client */
|
||||
bool isServer() const;
|
||||
[[nodiscard]] constexpr auto isServer() const noexcept
|
||||
{
|
||||
return session_ != nullptr;
|
||||
}
|
||||
|
||||
/** returns true if isServer() is true or if the remote address is the localhost */
|
||||
bool isLocal() const;
|
||||
[[nodiscard]] auto isLocal() const noexcept
|
||||
{
|
||||
return !session_id_.isEmpty() ? is_definitely_local_session_ : rpc_.isLocal();
|
||||
}
|
||||
|
||||
RpcResponseFuture exec(tr_quark method, tr_variant* args);
|
||||
RpcResponseFuture exec(std::string_view method, tr_variant* args);
|
||||
|
|
Loading…
Reference in a new issue