1 /**
2  * UGENE - Integrated Bioinformatics Tools.
3  * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru>
4  * http://ugene.net
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  */
21 
22 #ifndef _U2_CONVERT_FILES_FORMAT_WORKER_H_
23 #define _U2_CONVERT_FILES_FORMAT_WORKER_H_
24 
25 #include <U2Core/GUrl.h>
26 
27 #include <U2Lang/LocalDomain.h>
28 #include <U2Lang/WorkflowUtils.h>
29 
30 namespace U2 {
31 namespace LocalWorkflow {
32 
33 class ConvertFilesFormatPrompter;
34 typedef PrompterBase<ConvertFilesFormatPrompter> ConvertFilesFormatBase;
35 
36 class ConvertFilesFormatPrompter : public ConvertFilesFormatBase {
37     Q_OBJECT
38 public:
39     ConvertFilesFormatPrompter(Actor *p = 0)
ConvertFilesFormatBase(p)40         : ConvertFilesFormatBase(p) {
41     }
42 
43 protected:
44     QString composeRichDoc();
45 };  // ConvertFilesFormatPrompter
46 
47 class ConvertFilesFormatWorker : public BaseWorker {
48     Q_OBJECT
49 public:
50     ConvertFilesFormatWorker(Actor *a);
51     void init();
52     Task *tick();
53     void cleanup();
54 
55 private:
56     IntegralBus *inputUrlPort;
57     IntegralBus *outputUrlPort;
58     QString targetFormat;
59     QStringList selectedFormatExtensions;
60     QStringList excludedFormats;
61 
62 public slots:
63     void sl_taskFinished(Task *task);
64 
65 private:
66     bool ensureFileExists(const QString &url);
67     QString takeUrl();
68     QString detectFormat(const QString &url);
69     QString createWorkingDir(const QString &fileUrl);
70     void sendResult(const QString &url);
71     Task *getConvertTask(const QString &detectedFormat, const QString &url);
72 };  // ConvertFilesFormatWorker
73 
74 class ConvertFilesFormatWorkerFactory : public DomainFactory {
75     static const QString ACTOR_ID;
76 
77 public:
78     static void init();
ConvertFilesFormatWorkerFactory()79     ConvertFilesFormatWorkerFactory()
80         : DomainFactory(ACTOR_ID) {
81     }
createWorker(Actor * a)82     Worker *createWorker(Actor *a) {
83         return new ConvertFilesFormatWorker(a);
84     }
85 };  // ConvertFilesFormatWorkerFactory
86 
87 }  // namespace LocalWorkflow
88 }  // namespace U2
89 
90 #endif
91