Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F7890013
kazv-io.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
3 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
<QUrl>
#include
<QObject>
struct
KazvIOPrivate
{
QPointer
<
KazvIOManager
>
manager
;
float
progress
;
QUrl
url
;
};
KazvIO
::
KazvIO
(
QObject
*
parent
)
:
QObject
(
parent
)
,
m_d
(
new
KazvIOPrivate
)
{
connect
(
this
,
&
KazvIO
::
urlChanged
,
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
(
QPointer
<
KJob
>
job
)
{
connect
(
job
,
&
KJob
::
percentChanged
,
this
,
&
KazvIO
::
updatePercent
);
connect
(
job
,
&
KJob
::
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::download
(
QUrl
localFileUrl
)
{
auto
job
=
m_d
->
manager
->
startNewDownloadJob
(
m_d
->
url
,
localFileUrl
);
connectJob
(
qobject_cast
<
KJob
*>
(
job
));
}
/*
* This function is only applicable to a single thread,
* if the manager is located in other threads, please modify this function appropriately
*/
QString
KazvIO::upload
(
QUrl
localFileUrl
)
{
// TODO: Implement upload function
return
QString
();
}
/*
* 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
->
manager
->
suspendJob
(
m_d
->
url
);
}
/*
* 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
->
manager
->
resumeJob
(
m_d
->
url
);
}
/*
* 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
->
manager
->
cancelJob
(
m_d
->
url
);
Q_EMIT
failure
();
}
void
KazvIO::checkJob
()
{
auto
job
=
m_d
->
manager
->
getJob
(
m_d
->
url
);
if
(
!
job
.
isNull
())
{
updatePercent
(
job
,
job
->
percent
());
Q_EMIT
downloading
();
if
(
job
->
isSuspended
())
{
Q_EMIT
suspended
();
}
connectJob
(
qobject_cast
<
KJob
*>
(
job
));
}
}
float
KazvIO::progress
()
{
return
m_d
->
progress
;
}
QUrl
KazvIO::url
()
{
return
m_d
->
url
;
}
void
KazvIO::setUrl
(
QUrl
url
)
{
m_d
->
url
=
url
;
Q_EMIT
urlChanged
();
}
KazvIOManager
*
KazvIO::manager
()
{
return
m_d
->
manager
;
}
void
KazvIO::setManager
(
KazvIOManager
*
manager
)
{
m_d
->
manager
=
manager
;
Q_EMIT
managerChanged
();
}
void
KazvIO::updatePercent
(
KJob
*
/* job */
,
unsigned
long
percent
)
{
m_d
->
progress
=
1.0
*
percent
/
100
;
Q_EMIT
progressChanged
();
}
void
KazvIO::checkResult
(
KJob
*
job
)
{
if
(
job
->
error
())
{
Q_EMIT
failure
();
}
else
{
Q_EMIT
success
();
}
}
void
KazvIO::clearPercent
()
{
m_d
->
progress
=
0
;
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Thu, Oct 2, 2:51 AM (19 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
487019
Default Alt Text
kazv-io.cpp (3 KB)
Attached To
Mode
rK kazv
Attached
Detach File
Event Timeline
Log In to Comment