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 "DialogUtils.h"
23 
24 #include <QCoreApplication>
25 #include <QDir>
26 #include <QMessageBox>
27 #include <QWizard>
28 
29 #include <U2Core/AppContext.h>
30 #include <U2Core/DocumentImport.h>
31 #include <U2Core/DocumentModel.h>
32 #include <U2Core/FormatUtils.h>
33 #include <U2Core/Settings.h>
34 #include <U2Core/Task.h>
35 
36 #include <U2Gui/LastUsedDirHelper.h>
37 #include <U2Gui/U2FileDialog.h>
38 
39 namespace U2 {
40 
showProjectIsLockedWarning(QWidget * p)41 void DialogUtils::showProjectIsLockedWarning(QWidget *p) {
42     QMessageBox::critical(p, tr("Error"), tr("Project is locked"), QMessageBox::Ok, QMessageBox::NoButton);
43 }
44 
prepareFileFilter(const QString & name,const QStringList & exts,bool any,const QStringList & extra)45 QString DialogUtils::prepareFileFilter(const QString &name, const QStringList &exts, bool any, const QStringList &extra) {
46     return FormatUtils::prepareFileFilter(name, exts, any, extra);
47 }
48 
prepareDocumentsFileFilter(const DocumentFormatId & fid,bool any,const QStringList & extra)49 QString DialogUtils::prepareDocumentsFileFilter(const DocumentFormatId &fid, bool any, const QStringList &extra) {
50     return FormatUtils::prepareDocumentsFileFilter(fid, any, extra);
51 }
52 
prepareDocumentsFileFilter(bool any,const QStringList & extra)53 QString DialogUtils::prepareDocumentsFileFilter(bool any, const QStringList &extra) {
54     return FormatUtils::prepareDocumentsFileFilter(any, extra);
55 }
56 
prepareDocumentsFileFilter(const DocumentFormatConstraints & c,bool any)57 QString DialogUtils::prepareDocumentsFileFilter(const DocumentFormatConstraints &c, bool any) {
58     return FormatUtils::prepareDocumentsFileFilter(c, any);
59 }
60 
prepareDocumentsFileFilterByObjType(const GObjectType & t,bool any)61 QString DialogUtils::prepareDocumentsFileFilterByObjType(const GObjectType &t, bool any) {
62     return FormatUtils::prepareDocumentsFileFilterByObjType(t, any);
63 }
64 
setWizardMinimumSize(QWizard * wizard,const QSize & minimumSize)65 void DialogUtils::setWizardMinimumSize(QWizard *wizard, const QSize &minimumSize) {
66     QSize bestSize = minimumSize;
67     foreach (int pageId, wizard->pageIds()) {
68         QWizardPage *page = wizard->page(pageId);
69         page->adjustSize();
70         bestSize = bestSize.expandedTo(page->size());
71     }
72     wizard->setMinimumSize(bestSize);
73     wizard->adjustSize();
74 }
75 
76 /********************************
77  * FileLineEdit
78  ********************************/
sl_onBrowse()79 void FileLineEdit::sl_onBrowse() {
80     LastUsedDirHelper lod(type);
81 
82     QFileDialog::Options options = 0;
83     if (qgetenv(ENV_GUI_TEST).toInt() == 1 && qgetenv(ENV_USE_NATIVE_DIALOGS).toInt() == 0) {
84         options |= QFileDialog::DontUseNativeDialog;
85     }
86 
87     QString name;
88     if (multi) {
89         QStringList lst = U2FileDialog::getOpenFileNames(nullptr, tr("Select file(s)"), lod.dir, FileFilter, nullptr, options);
90         name = lst.join(";");
91         if (!lst.isEmpty()) {
92             lod.url = lst.first();
93         }
94     } else {
95         lod.url = name = U2FileDialog::getOpenFileName(nullptr, tr("Select file(s)"), lod.dir, FileFilter, nullptr, options);
96     }
97     if (!name.isEmpty()) {
98         setText(name);
99     }
100     setFocus();
101 }
102 
103 }  // namespace U2
104