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 #include "ExportBlastResultDialog.h"
23 
24 #include <QMessageBox>
25 #include <QPushButton>
26 
27 #include <U2Core/AppContext.h>
28 #include <U2Core/BaseDocumentFormats.h>
29 #include <U2Core/L10n.h>
30 #include <U2Core/Settings.h>
31 
32 #include <U2Gui/DialogUtils.h>
33 #include <U2Gui/HelpButton.h>
34 #include <U2Gui/SaveDocumentController.h>
35 
36 namespace U2 {
37 
ExportBlastResultDialog(QWidget * p,const QString & defaultUrl)38 ExportBlastResultDialog::ExportBlastResultDialog(QWidget *p, const QString &defaultUrl)
39     : QDialog(p),
40       saveController(nullptr) {
41     setupUi(this);
42     new HelpButton(this, buttonBox, "65930715");
43     buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Export"));
44     buttonBox->button(QDialogButtonBox::Cancel)->setText(tr("Cancel"));
45 
46     addToProjectFlag = true;
47 
48     nameIdBox->addItem("accession");
49     nameIdBox->addItem("def");
50     nameIdBox->addItem("id");
51 
52     nameIdBox->setCurrentIndex(0);
53 
54     initSaveController(defaultUrl);
55 }
56 
accept()57 void ExportBlastResultDialog::accept() {
58     if (saveController->getSaveFileName().isEmpty()) {
59         QMessageBox::critical(this, L10N::errorTitle(), tr("File name is empty!"));
60         return;
61     }
62 
63     url = saveController->getSaveFileName();
64     format = saveController->getFormatIdToSave();
65     addToProjectFlag = addToProjectBox->isChecked();
66     qualiferId = nameIdBox->currentText();
67     addRefFlag = addRefBox->isChecked();
68     QDialog::accept();
69 }
70 
initSaveController(const QString & defaultUrl)71 void ExportBlastResultDialog::initSaveController(const QString &defaultUrl) {
72     SaveDocumentControllerConfig config;
73     config.defaultFileName = defaultUrl;
74     config.defaultFormatId = BaseDocumentFormats::CLUSTAL_ALN;
75     config.fileDialogButton = fileButton;
76     config.fileNameEdit = fileNameEdit;
77     config.formatCombo = formatCombo;
78     config.parentWidget = this;
79 
80     DocumentFormatConstraints formatConstraints;
81     formatConstraints.supportedObjectTypes << GObjectTypes::MULTIPLE_SEQUENCE_ALIGNMENT;
82     formatConstraints.addFlagToSupport(DocumentFormatFlag_SupportWriting);
83 
84     saveController = new SaveDocumentController(config, formatConstraints, this);
85 }
86 
setOkButtonText(const QString & text) const87 void ExportBlastResultDialog::setOkButtonText(const QString &text) const {
88     QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
89     okButton->setText(text);
90 }
91 
setFileLabelText(const QString & text) const92 void ExportBlastResultDialog::setFileLabelText(const QString &text) const {
93     fileLabel->setText(text);
94 }
95 
96 }  // namespace U2
97