Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F7888844
kazv-io.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
kazv-io.cpp
View Options
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2022 nannanko <nannanko@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include
"kazv-io.hpp"
#include
"kazv-io-manager.hpp"
#include
"kazv-io-job.hpp"
#include
<QUrl>
#include
<QObject>
struct
KazvIOPrivate
{
float
progress
;
QPointer
<
KazvIOBaseJob
>
kazvIOJob
;
};
KazvIO
::
KazvIO
(
QObject
*
parent
)
:
QObject
(
parent
)
,
m_d
(
new
KazvIOPrivate
)
{
connect
(
this
,
&
KazvIO
::
jobChanged
,
this
,
&
KazvIO
::
checkJob
);
connect
(
this
,
&
KazvIO
::
success
,
this
,
&
KazvIO
::
result
);
connect
(
this
,
&
KazvIO
::
failure
,
this
,
&
KazvIO
::
result
);
connect
(
this
,
&
KazvIO
::
result
,
this
,
&
KazvIO
::
clearPercent
);
}
KazvIO
::~
KazvIO
()
=
default
;
void
KazvIO::connectJob
()
{
connect
(
m_d
->
kazvIOJob
->
job
(),
&
KJob
::
percentChanged
,
this
,
&
KazvIO
::
updateProgress
);
connect
(
m_d
->
kazvIOJob
,
&
KazvIOBaseJob
::
result
,
this
,
&
KazvIO
::
checkResult
);
}
/*
* This function is only applicable to a single thread,
* if the manager is located in other threads, please modify this function appropriately
*/
void
KazvIO::suspend
()
{
m_d
->
kazvIOJob
->
job
()
->
suspend
();
}
/*
* This function is only applicable to a single thread,
* if the manager is located in other threads, please modify this function appropriately
*/
void
KazvIO::resume
()
{
m_d
->
kazvIOJob
->
job
()
->
resume
();
}
/*
* This function is only applicable to a single thread,
* if the manager is located in other threads, please modify this function appropriately
*/
void
KazvIO::cancel
()
{
m_d
->
kazvIOJob
->
job
()
->
kill
();
Q_EMIT
failure
();
}
void
KazvIO::checkJob
()
{
if
(
m_d
->
kazvIOJob
.
isNull
())
{
return
;
}
Q_EMIT
processing
();
if
(
m_d
->
kazvIOJob
->
success
().
has_value
())
{
checkResult
();
return
;
}
updateProgress
(
m_d
->
kazvIOJob
->
job
(),
m_d
->
kazvIOJob
->
job
()
->
percent
());
if
(
m_d
->
kazvIOJob
->
job
()
->
isSuspended
())
{
Q_EMIT
suspended
();
}
connectJob
();
}
float
KazvIO::progress
()
{
return
m_d
->
progress
;
}
void
KazvIO::updateProgress
(
KJob
*
/* job */
,
unsigned
long
percent
)
{
m_d
->
progress
=
1.0
*
percent
/
100
;
Q_EMIT
progressChanged
();
}
void
KazvIO::checkResult
()
{
if
(
m_d
->
kazvIOJob
->
error
().
value
())
{
Q_EMIT
failure
();
}
else
{
Q_EMIT
success
();
}
}
void
KazvIO::clearPercent
()
{
m_d
->
progress
=
0
;
Q_EMIT
progressChanged
();
}
KazvIOBaseJob
*
KazvIO::job
()
{
return
m_d
->
kazvIOJob
;
}
void
KazvIO::setJob
(
KazvIOBaseJob
*
job
)
{
m_d
->
kazvIOJob
=
job
;
Q_EMIT
jobChanged
();
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Thu, Oct 2, 2:10 AM (5 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
478327
Default Alt Text
kazv-io.cpp (2 KB)
Attached To
Mode
rK kazv
Attached
Detach File
Event Timeline
Log In to Comment