2
* UGENE - Integrated Bioinformatics Tools.
3
* Copyright (C) 2008-2011 UniPro <ugene@unipro.ru>
4
* http://ugene.unipro.ru
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.
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.
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,
22
#include "BuildIndexDialog.h"
23
#include "DnaAssemblyGUIExtension.h"
25
#include <U2Algorithm/DnaAssemblyAlgRegistry.h>
26
#include <U2Core/GUrlUtils.h>
27
#include <U2Misc/DialogUtils.h>
28
#include <U2Core/DocumentUtils.h>
30
#include <QtGui/QFileDialog>
31
#include <QtGui/QMessageBox>
36
QString BuildIndexDialog::genomePath;
38
BuildIndexDialog::BuildIndexDialog(const DnaAssemblyAlgRegistry* registry, QWidget* p)
39
: QDialog(p), assemblyRegistry(registry), customGUI(NULL)
42
QStringList names = registry->getRegisteredAlgorithmsWithIndexFileSupport();
43
methodNamesBox->addItems(names);
44
// TODO: change the way default method is set
45
if (names.size() > 0) {
46
methodNamesBox->setCurrentIndex(names.size() - 1);
48
sl_onAlgorithmChanged(methodNamesBox->currentText());
49
connect(setIndexFileNameButton, SIGNAL(clicked()), SLOT(sl_onSetIndexFileNameButtonClicked()));
50
connect(addRefButton, SIGNAL(clicked()), SLOT(sl_onAddRefButtonClicked()) );
51
connect(methodNamesBox, SIGNAL(currentIndexChanged(const QString &)), SLOT(sl_onAlgorithmChanged(const QString &)));
53
if (!genomePath.isEmpty()) {
54
refSeqEdit->setText(genomePath);
55
buildIndexUrl(genomePath);
59
void BuildIndexDialog::sl_onAddRefButtonClicked() {
60
LastOpenDirHelper lod;
63
lod.url = QFileDialog::getOpenFileName(this, tr("Open reference sequence"), lod.dir, filter);
64
if (lod.url.isEmpty()) {
68
refSeqEdit->setText(lod.url);
69
buildIndexUrl(lod.url);
72
void BuildIndexDialog::sl_onSetIndexFileNameButtonClicked() {
73
LastOpenDirHelper lod;
74
lod.url = QFileDialog::getSaveFileName(this, tr("Set index file name"), lod.dir);
75
if (!lod.url.isEmpty()) {
77
if (index.lastFileSuffix().isEmpty() && customGUI != NULL) {
78
QString extension = customGUI->getIndexFileExtension();
79
if (extension.isEmpty()) {
80
index = QString( "%1" ).arg( index.getURLString() );
82
index = QString( "%1.%2" ).arg( index.getURLString() ).arg(extension);
85
indexFileNameEdit->setText(index.getURLString());
89
void BuildIndexDialog::sl_onAlgorithmChanged(const QString &) {
93
void BuildIndexDialog::updateState() {
97
void BuildIndexDialog::addGuiExtension() {
98
int insertPos = verticalLayout->count() - 2;
100
// cleanup previous extension
101
if (customGUI != NULL) {
102
layout()->removeWidget(customGUI);
103
setMinimumHeight(minimumHeight() - customGUI->minimumHeight());
108
// insert new extension widget
109
DnaAssemblyAlgorithmEnv* env = assemblyRegistry->getAlgorithm(methodNamesBox->currentText());
114
DnaAssemblyGUIExtensionsFactory* gui = env->getGUIExtFactory();
115
if (gui!=NULL && gui->hasBuildIndexWidget()) {
116
customGUI = gui->createBuildIndexWidget(this);
117
int extensionMinWidth = customGUI->sizeHint().width();
118
int extensionMinHeight = customGUI->sizeHint().height();
119
customGUI->setMinimumWidth(extensionMinWidth);
120
customGUI->setMinimumHeight(extensionMinHeight);
121
verticalLayout->insertWidget(insertPos, customGUI);
123
setMinimumHeight(customGUI->minimumHeight() + minimumHeight());
124
if (minimumWidth() < customGUI->minimumWidth()) {
125
setMinimumWidth(customGUI->minimumWidth());
127
if (!refSeqEdit->text().isEmpty()) {
128
buildIndexUrl(refSeqEdit->text());
136
void BuildIndexDialog::buildIndexUrl(const GUrl& refUrl ) {
137
QString extension("");
138
if (NULL != customGUI) {
139
extension = customGUI->getIndexFileExtension();
140
customGUI->buildIndexUrl(refUrl);
143
if (extension.isEmpty()) {
144
url = GUrlUtils::rollFileName(refUrl.dirPath() + "/" + refUrl.baseFileName(), DocumentUtils::getNewDocFileNameExcludesHint());
146
url = GUrlUtils::rollFileName(refUrl.dirPath() + "/" + refUrl.baseFileName()+ "." + extension, DocumentUtils::getNewDocFileNameExcludesHint());
149
indexFileNameEdit->setText(url.getURLString());
152
void BuildIndexDialog::accept()
154
if (refSeqEdit->text().isEmpty()) {
155
QMessageBox::information(this, tr("Build index"), tr("Reference sequence url is not set!") );
156
} else if (indexFileNameEdit->text().isEmpty() ) {
157
QMessageBox::information(this, tr("Build index"), tr("Index file name is not set!") );
160
genomePath = refSeqEdit->text();
166
const GUrl BuildIndexDialog::getRefSeqUrl() {
167
return refSeqEdit->text();
170
const QString BuildIndexDialog::getAlgorithmName() {
171
return methodNamesBox->currentText();
174
const QString BuildIndexDialog::getIndexFileName() {
175
return indexFileNameEdit->text();
178
QMap<QString, QVariant> BuildIndexDialog::getCustomSettings() {
179
if (customGUI != NULL) {
180
return customGUI->getBuildIndexCustomSettings();
182
return QMap<QString, QVariant>();