1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2015-06-15
7  * Description : Manager for creating and starting IO jobs threads
8  *
9  * Copyright (C) 2015 by Mohamed_Anwer <m_dot_anwer at gmx dot com>
10  * Copyright (C) 2018 by Maik Qualmann <metzpinguin at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #include "iojobsmanager.h"
26 
27 // Local includes
28 
29 #include "iojobdata.h"
30 
31 namespace Digikam
32 {
33 
34 class Q_DECL_HIDDEN IOJobsManagerCreator
35 {
36 public:
37 
38     IOJobsManager object;
39 };
40 
Q_GLOBAL_STATIC(IOJobsManagerCreator,creator)41 Q_GLOBAL_STATIC(IOJobsManagerCreator, creator)
42 
43 // ----------------------------------------------
44 
45 IOJobsManager::IOJobsManager()
46 {
47 }
48 
instance()49 IOJobsManager* IOJobsManager::instance()
50 {
51     return (&creator->object);
52 }
53 
startIOJobs(IOJobData * const data)54 IOJobsThread* IOJobsManager::startIOJobs(IOJobData* const data)
55 {
56     IOJobsThread* const thread = new IOJobsThread(this);
57 
58     switch (data->operation())
59     {
60         case IOJobData::CopyAlbum:
61         case IOJobData::CopyImage:
62         case IOJobData::CopyFiles:
63         case IOJobData::CopyToExt:
64         case IOJobData::MoveAlbum:
65         case IOJobData::MoveImage:
66         case IOJobData::MoveFiles:
67             thread->copyOrMove(data);
68             break;
69 
70         case IOJobData::Trash:
71         case IOJobData::Delete:
72             thread->deleteFiles(data);
73             break;
74 
75         case IOJobData::Rename:
76             thread->renameFile(data);
77             break;
78 
79         case IOJobData::Restore:
80             thread->restoreDTrashItems(data);
81             break;
82 
83         case IOJobData::Empty:
84             thread->emptyDTrashItems(data);
85             break;
86 
87         default:
88             break;
89     }
90 
91     connect(thread, SIGNAL(signalFinished()),
92             thread, SLOT(deleteLater()),
93             Qt::QueuedConnection);
94 
95     thread->start();
96 
97     return thread;
98 }
99 
startDTrashItemsListingForCollection(const QString & collectionPath)100 IOJobsThread* IOJobsManager::startDTrashItemsListingForCollection(const QString& collectionPath)
101 {
102     IOJobsThread* const thread = new IOJobsThread(this);
103     thread->listDTrashItems(collectionPath);
104 
105     connect(thread, SIGNAL(signalFinished()),
106             thread, SLOT(deleteLater()),
107             Qt::QueuedConnection);
108 
109     thread->start();
110 
111     return thread;
112 }
113 
114 } // namespace Digikam
115