~ubuntu-branches/ubuntu/utopic/kdevplatform/utopic-proposed

« back to all changes in this revision

Viewing changes to plugins/bazaar/copyjob.cpp

  • Committer: Package Import Robot
  • Author(s): Scarlett Clark
  • Date: 2014-08-30 03:52:11 UTC
  • mfrom: (0.3.26)
  • Revision ID: package-import@ubuntu.com-20140830035211-wndqlc843eu2v8nk
Tags: 1.7.0-0ubuntu1
* New upstream release
* Add XS-Testsuite: autopkgtest

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright 2013-2014 Maciej Poleski                                    *
 
3
 *                                                                         *
 
4
 *   This program is free software; you can redistribute it and/or         *
 
5
 *   modify it under the terms of the GNU General Public License as        *
 
6
 *   published by the Free Software Foundation; either version 2 of        *
 
7
 *   the License or (at your option) version 3 or any later version        *
 
8
 *   accepted by the membership of KDE e.V. (or its successor approved     *
 
9
 *   by the membership of KDE e.V.), which shall act as a proxy            *
 
10
 *   defined in Section 14 of version 3 of the license.                    *
 
11
 *                                                                         *
 
12
 *   This program is distributed in the hope that it will be useful,       *
 
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
15
 *   GNU General Public License for more details.                          *
 
16
 *                                                                         *
 
17
 *   You should have received a copy of the GNU General Public License     *
 
18
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 
19
 ***************************************************************************/
 
20
 
 
21
#include "copyjob.h"
 
22
 
 
23
#include <QtCore/QVariant>
 
24
 
 
25
#include <KIO/CopyJob>
 
26
 
 
27
#include <interfaces/iplugin.h>
 
28
#include <vcs/dvcs/dvcsjob.h>
 
29
 
 
30
#include "bazaarplugin.h"
 
31
 
 
32
CopyJob::CopyJob(const KUrl& localLocationSrc, const KUrl& localLocationDstn, BazaarPlugin* parent, KDevelop::OutputJob::OutputJobVerbosity verbosity)
 
33
    : VcsJob(parent, verbosity), m_plugin(parent), m_source(localLocationSrc),
 
34
      m_destination(localLocationDstn), m_status(KDevelop::VcsJob::JobNotStarted)
 
35
{
 
36
    setType(JobType::Copy);
 
37
    setCapabilities(Killable);
 
38
}
 
39
 
 
40
 
 
41
KDevelop::IPlugin* CopyJob::vcsPlugin() const
 
42
{
 
43
    return m_plugin;
 
44
}
 
45
 
 
46
KDevelop::VcsJob::JobStatus CopyJob::status() const
 
47
{
 
48
    return m_status;
 
49
}
 
50
 
 
51
QVariant CopyJob::fetchResults()
 
52
{
 
53
    return QVariant();
 
54
}
 
55
 
 
56
void CopyJob::start()
 
57
{
 
58
    if (m_status != KDevelop::VcsJob::JobNotStarted)
 
59
        return;
 
60
    KIO::CopyJob* job = KIO::copy(m_source, m_destination, KIO::HideProgressInfo);
 
61
    connect(job, SIGNAL(copyingDone(KIO::Job*, KUrl, KUrl, time_t, bool, bool)), this, SLOT(addToVcs(KIO::Job*, KUrl, KUrl, time_t, bool, bool)));
 
62
    m_status = KDevelop::VcsJob::JobRunning;
 
63
    m_job = job;
 
64
    job->start();
 
65
}
 
66
 
 
67
bool CopyJob::doKill()
 
68
{
 
69
    m_status = KDevelop::VcsJob::JobCanceled;
 
70
    if (m_job)
 
71
        return m_job->kill(KJob::Quietly);
 
72
    else
 
73
        return true;
 
74
}
 
75
 
 
76
void CopyJob::addToVcs(KIO::Job* job, const KUrl& from, const KUrl& to, time_t mtime, bool directory, bool renamed)
 
77
{
 
78
    Q_UNUSED(job);
 
79
    Q_UNUSED(from);
 
80
    Q_UNUSED(mtime);
 
81
    Q_UNUSED(directory);
 
82
    Q_UNUSED(renamed);
 
83
    if (m_status != KDevelop::VcsJob::JobRunning)
 
84
        return;
 
85
    KDevelop::VcsJob* job2 = m_plugin->add(to, KDevelop::IBasicVersionControl::Recursive);
 
86
    connect(job2, SIGNAL(result(KJob*)), this, SLOT(finish(KJob*)));
 
87
    m_job = job2;
 
88
    job2->start();
 
89
}
 
90
 
 
91
void CopyJob::finish(KJob*)
 
92
{
 
93
    m_status = KDevelop::VcsJob::JobSucceeded;
 
94
    emitResult();
 
95
    emit resultsReady(this);
 
96
}
 
97
 
 
98
 
 
99
#include "copyjob.moc"