File indexing completed on 2024-05-05 08:28:04
0001 /* SPDX-FileCopyrightText: 2012 Jesper K. Pedersen <blackie@kde.org> 0002 0003 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 #include "JobInfo.h" 0007 0008 #include <KLocalizedString> 0009 0010 namespace BackgroundTaskManager 0011 { 0012 0013 int JobInfo::s_jobCounter = 0; 0014 0015 JobInfo::JobInfo(BackgroundTaskManager::Priority priority) 0016 : state(NotStarted) 0017 , m_priority(priority) 0018 , m_elapsed(0) 0019 , m_jobIndex(++s_jobCounter) 0020 { 0021 } 0022 0023 JobInfo::JobInfo(const JobInfo *other) 0024 { 0025 m_priority = other->m_priority; 0026 state = other->state; 0027 m_elapsed = other->m_elapsed; 0028 m_jobIndex = other->m_jobIndex; 0029 } 0030 0031 JobInfo::~JobInfo() 0032 { 0033 } 0034 0035 Priority JobInfo::priority() const 0036 { 0037 return m_priority; 0038 } 0039 0040 void JobInfo::start() 0041 { 0042 m_timer.start(); 0043 state = Running; 0044 } 0045 0046 void JobInfo::stop() 0047 { 0048 m_elapsed = m_timer.elapsed(); 0049 state = Completed; 0050 } 0051 0052 QString JobInfo::elapsed() const 0053 { 0054 if (state == NotStarted) 0055 return i18n("Not Started"); 0056 0057 qint64 time = m_timer.elapsed(); 0058 if (state == Completed) 0059 time = m_elapsed; 0060 0061 const int secs = time / 1000; 0062 const int part = (time % 1000) / 100; 0063 0064 return QString::fromLatin1("%1.%2").arg(secs).arg(part); 0065 } 0066 0067 int JobInfo::jobIndex() const 0068 { 0069 return m_jobIndex; 0070 } 0071 0072 } 0073 // vi:expandtab:tabstop=4 shiftwidth=4: 0074 0075 #include "moc_JobInfo.cpp"