<commit_before>//  Powiter
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
 *Created by <NAME> on 6/1/2012.
 *contact: immarespond at gmail dot com
 *
 */


#include "SequenceFileDialog.h"

#include <cassert>
#include <locale>
#include <algorithm>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMessageBox>
#include <QtGui/QPainter>
#include <QListView>
#include <QHeaderView>
#include <QCheckBox>
#include <QLabel>
#include <QFileIconProvider>
#include <QInputDialog>
#include <QSplitter>
#include <QtGui/QIcon>
#include <QtCore/QRegExp>
#include <QtGui/QKeyEvent>
#include <QtGui/QColor>
#if QT_VERSION < 0x050000
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QStylePainter>
#include <QtGui/QStyleOptionViewItem>
#else
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QStylePainter>
#include <QtWidgets/QStyleOptionViewItem>
#endif
#include <QMenu>

#include <QtCore/QEvent>
#include <QtCore/QMimeData>
#include <QtConcurrentRun>

#include <QtCore/QSettings>

#include "Gui/Button.h"
#include "Gui/LineEdit.h"
#include "Gui/ComboBox.h"
#include "Global/GlobalDefines.h"
#include "Global/MemoryInfo.h"

using namespace std;

static inline bool nocase_equal_char (char c1, char c2)
{
    return toupper(c1) == toupper(c2);
}

static inline bool nocase_equal_string (const std::string &s1, const std::string &s2)
{
    return s1.size() == s2.size() &&        // ensure same sizes
    std::equal (s1.begin(),s1.end(),      // first source string
                s2.begin(),               // second source string
                nocase_equal_char);
}

SequenceFileDialog::SequenceFileDialog(QWidget* parent, // necessary to transmit the stylesheet to the dialog
                                       const std::vector<std::string>& filters, // the user accepted file types
                                       bool isSequenceDialog, // true if this dialog can display sequences
                                       FileDialogMode mode, // if it is an open or save dialog
                                       const std::string& currentDirectory): // the directory to show first
QDialog(parent),
_filters(filters),
_currentHistoryLocation(-1),
_dialogMode(mode)
{
    setWindowFlags(Qt::Window);
    _mainLayout = new QVBoxLayout(this);
    setLayout(_mainLayout);
    /*Creating view and setting directory*/
    _view =  new SequenceDialogView(this);
    _itemDelegate = new SequenceItemDelegate(this);
    _proxy = new SequenceDialogProxyModel(this);
    _model = new QFileSystemModel();
    _proxy->setSourceModel(_model);
    _view->setModel(_proxy);
    _view->setItemDelegate(_itemDelegate);
    QObject::connect(_model,SIGNAL(directoryLoaded(QString)),this,SLOT(updateView(QString)));
    QObject::connect(_view, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(doubleClickOpen(QModelIndex)));
    
    /*creating GUI*/
    _buttonsWidget = new QWidget(this);
    _buttonsLayout = new QHBoxLayout(_buttonsWidget);
    _buttonsWidget->setLayout(_buttonsLayout);
    if(mode == OPEN_DIALOG)
        _lookInLabel = new QLabel("Look in:",_buttonsWidget);
    else
        _lookInLabel = new QLabel("Save in:",_buttonsWidget);
    _buttonsLayout->addWidget(_lookInLabel);
    
    _lookInCombobox = new FileDialogComboBox(_buttonsWidget);
    _buttonsLayout->addWidget(_lookInCombobox);
    _lookInCombobox->setFileDialogPointer(this);
    QObject::connect(_lookInCombobox, SIGNAL(activated(QString)), this, SLOT(goToDirectory(QString)));
    _lookInCombobox->setInsertPolicy(QComboBox::NoInsert);
    _lookInCombobox->setDuplicatesEnabled(false);
    
    _lookInCombobox->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Fixed);
    
    _buttonsLayout->addStretch();
    
    
    _previousButton = new Button(style()->standardIcon(QStyle::SP_ArrowBack),"",_buttonsWidget);
    _buttonsLayout->addWidget(_previousButton);
    QObject::connect(_previousButton, SIGNAL(clicked()), this, SLOT(previousFolder()));
    
    _nextButton = new Button(style()->standardIcon(QStyle::SP_ArrowForward),"",_buttonsWidget);
    _buttonsLayout->addWidget(_nextButton);
    QObject::connect(_nextButton, SIGNAL(clicked()), this, SLOT(nextFolder()));
    
    _upButton = new Button(style()->standardIcon(QStyle::SP_ArrowUp),"",_buttonsWidget);
    _buttonsLayout->addWidget(_upButton);
    QObject::connect(_upButton, SIGNAL(clicked()), this, SLOT(parentFolder()));
    
    _createDirButton = new Button(style()->standardIcon(QStyle::SP_FileDialogNewFolder),"",_buttonsWidget);
    _buttonsLayout->addWidget(_createDirButton);
    QObject::connect(_createDirButton, SIGNAL(clicked()), this, SLOT(createDir()));
    
    
    _previewButton = new Button("preview",_buttonsWidget);
    _previewButton->setVisible(false);/// @todo Implement preview mode for the file dialog
    _buttonsLayout->addWidget(_previewButton);
    
    
    _mainLayout->addWidget(_buttonsWidget);
    
    /*creating center*/
    _centerSplitter = new QSplitter(this);
    _centerSplitter->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    
    _favoriteWidget = new QWidget(this);
    _favoriteLayout = new QVBoxLayout(_favoriteWidget);
    _favoriteWidget->setLayout(_favoriteLayout);
    _favoriteView = new FavoriteView(this);
    QObject::connect(_favoriteView,SIGNAL(urlRequested(QUrl)),this,SLOT(seekUrl(QUrl)));
    _favoriteLayout->setSpacing(0);
    _favoriteLayout->setContentsMargins(0, 0, 0, 0);
    _favoriteLayout->addWidget(_favoriteView);
    
    _favoriteButtonsWidget = new QWidget(_favoriteView);
    _favoriteButtonsLayout = new QHBoxLayout(_favoriteButtonsWidget);
    // _favoriteButtonsLayout->setSpacing(0);
    _favoriteButtonsLayout->setContentsMargins(0,0,0,0);
    _favoriteButtonsWidget->setLayout(_favoriteButtonsLayout);
    
    _addFavoriteButton = new Button("+",this);
    _addFavoriteButton->setMaximumSize(20,20);
    _favoriteButtonsLayout->addWidget(_addFavoriteButton);
    QObject::connect(_addFavoriteButton, SIGNAL(clicked()), this, SLOT(addFavorite()));
    
    _removeFavoriteButton = new Button("-",this);
    _removeFavoriteButton->setMaximumSize(20,20);
    _favoriteButtonsLayout->addWidget(_removeFavoriteButton);
    QObject::connect(_removeFavoriteButton, SIGNAL(clicked()), _favoriteView, SLOT(removeEntry()));
    
    _favoriteButtonsLayout->addStretch();
    
    _favoriteLayout->addWidget(_favoriteButtonsWidget);
    
    
    _centerSplitter->addWidget(_favoriteWidget);
    _centerSplitter->addWidget(_view);
    
    _mainLayout->addWidget(_centerSplitter);
    
    /*creating selection widget*/
    _selectionWidget = new QWidget(this);
    _selectionLayout = new QHBoxLayout(_selectionWidget);
    _selectionLayout->setContentsMargins(0, 0, 0, 0);
    _selectionWidget->setLayout(_selectionLayout);
    
    _sequenceButton = new ComboBox(_buttonsWidget);
    _sequenceButton->addItem("Sequences");
    _sequenceButton->addItem("File");
    if(isSequenceDialog){
        _sequenceButton->setCurrentIndex(0);
    }else{
        _sequenceButton->setCurrentIndex(1);
    }
    QObject::connect(_sequenceButton,SIGNAL(currentIndexChanged(QString)),this,SLOT(sequenceComboBoxSlot(QString)));
    _selectionLayout->addWidget(_sequenceButton);
    
    if(!isSequenceDialog){
        _sequenceButton->setVisible(false);
    }
    _selectionLineEdit = new LineEdit(_selectionWidget);
    _selectionLayout->addWidget(_selectionLineEdit);
    
    if(mode==SequenceFileDialog::OPEN_DIALOG)
        _openButton = new Button("Open",_selectionWidget);
    else
        _openButton = new Button("Save",_selectionWidget);
    _selectionLayout->addWidget(_openButton);
    QObject::connect(_openButton, SIGNAL(pressed()), this, SLOT(openSelectedFiles()));
    
    _mainLayout->addWidget(_selectionWidget);
    
    /*creating filter zone*/
    _filterLineWidget = new QWidget(this);
    _filterLineLayout = new QHBoxLayout(_filterLineWidget);
    _filterLineLayout->setContentsMargins(0, 0, 0, 0);
    _filterLineWidget->setLayout(_filterLineLayout);<commit_msg>we are opening only one sequence<commit_after>//  Powiter
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
 *Created by <NAME> on 6/1/2012.
 *contact: <EMAIL>
 *
 */


#include "SequenceFileDialog.h"

#include <cassert>
#include <locale>
#include <algorithm>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMessageBox>
#include <QtGui/QPainter>
#include <QListView>
#include <QHeaderView>
#include <QCheckBox>
#include <QLabel>
#include <QFileIconProvider>
#include <QInputDialog>
#include <QSplitter>
#include <QtGui/QIcon>
#include <QtCore/QRegExp>
#include <QtGui/QKeyEvent>
#include <QtGui/QColor>
#if QT_VERSION < 0x050000
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QStylePainter>
#include <QtGui/QStyleOptionViewItem>
#else
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QStylePainter>
#include <QtWidgets/QStyleOptionViewItem>
#endif
#include <QMenu>

#include <QtCore/QEvent>
#include <QtCore/QMimeData>
#include <QtConcurrentRun>

#include <QtCore/QSettings>

#include "Gui/Button.h"
#include "Gui/LineEdit.h"
#include "Gui/ComboBox.h"
#include "Global/GlobalDefines.h"
#include "Global/MemoryInfo.h"

using namespace std;

static inline bool nocase_equal_char (char c1, char c2)
{
    return toupper(c1) == toupper(c2);
}

static inline bool nocase_equal_string (const std::string &s1, const std::string &s2)
{
    return s1.size() == s2.size() &&        // ensure same sizes
    std::equal (s1.begin(),s1.end(),      // first source string
                s2.begin(),               // second source string
                nocase_equal_char);
}

SequenceFileDialog::SequenceFileDialog(QWidget* parent, // necessary to transmit the stylesheet to the dialog
                                       const std::vector<std::string>& filters, // the user accepted file types
                                       bool isSequenceDialog, // true if this dialog can display sequences
                                       FileDialogMode mode, // if it is an open or save dialog
                                       const std::string& currentDirectory): // the directory to show first
QDialog(parent),
_filters(filters),
_currentHistoryLocation(-1),
_dialogMode(mode)
{
    setWindowFlags(Qt::Window);
    _mainLayout = new QVBoxLayout(this);
    setLayout(_mainLayout);
    /*Creating view and setting directory*/
    _view =  new SequenceDialogView(this);
    _itemDelegate = new SequenceItemDelegate(this);
    _proxy = new SequenceDialogProxyModel(this);
    _model = new QFileSystemModel();
    _proxy->setSourceModel(_model);
    _view->setModel(_proxy);
    _view->setItemDelegate(_itemDelegate);
    QObject::connect(_model,SIGNAL(directoryLoaded(QString)),this,SLOT(updateView(QString)));
    QObject::connect(_view, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(doubleClickOpen(QModelIndex)));
    
    /*creating GUI*/
    _buttonsWidget = new QWidget(this);
    _buttonsLayout = new QHBoxLayout(_buttonsWidget);
    _buttonsWidget->setLayout(_buttonsLayout);
    if(mode == OPEN_DIALOG)
        _lookInLabel = new QLabel("Look in:",_buttonsWidget);
    else
        _lookInLabel = new QLabel("Save in:",_buttonsWidget);
    _buttonsLayout->addWidget(_lookInLabel);
    
    _lookInCombobox = new FileDialogComboBox(_buttonsWidget);
    _buttonsLayout->addWidget(_lookInCombobox);
    _lookInCombobox->setFileDialogPointer(this);
    QObject::connect(_lookInCombobox, SIGNAL(activated(QString)), this, SLOT(goToDirectory(QString)));
    _lookInCombobox->setInsertPolicy(QComboBox::NoInsert);
    _lookInCombobox->setDuplicatesEnabled(false);
    
    _lookInCombobox->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Fixed);
    
    _buttonsLayout->addStretch();
    
    
    _previousButton = new Button(style()->standardIcon(QStyle::SP_ArrowBack),"",_buttonsWidget);
    _buttonsLayout->addWidget(_previousButton);
    QObject::connect(_previousButton, SIGNAL(clicked()), this, SLOT(previousFolder()));
    
    _nextButton = new Button(style()->standardIcon(QStyle::SP_ArrowForward),"",_buttonsWidget);
    _buttonsLayout->addWidget(_nextButton);
    QObject::connect(_nextButton, SIGNAL(clicked()), this, SLOT(nextFolder()));
    
    _upButton = new Button(style()->standardIcon(QStyle::SP_ArrowUp),"",_buttonsWidget);
    _buttonsLayout->addWidget(_upButton);
    QObject::connect(_upButton, SIGNAL(clicked()), this, SLOT(parentFolder()));
    
    _createDirButton = new Button(style()->standardIcon(QStyle::SP_FileDialogNewFolder),"",_buttonsWidget);
    _buttonsLayout->addWidget(_createDirButton);
    QObject::connect(_createDirButton, SIGNAL(clicked()), this, SLOT(createDir()));
    
    
    _previewButton = new Button("preview",_buttonsWidget);
    _previewButton->setVisible(false);/// @todo Implement preview mode for the file dialog
    _buttonsLayout->addWidget(_previewButton);
    
    
    _mainLayout->addWidget(_buttonsWidget);
    
    /*creating center*/
    _centerSplitter = new QSplitter(this);
    _centerSplitter->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    
    _favoriteWidget = new QWidget(this);
    _favoriteLayout = new QVBoxLayout(_favoriteWidget);
    _favoriteWidget->setLayout(_favoriteLayout);
    _favoriteView = new FavoriteView(this);
    QObject::connect(_favoriteView,SIGNAL(urlRequested(QUrl)),this,SLOT(seekUrl(QUrl)));
    _favoriteLayout->setSpacing(0);
    _favoriteLayout->setContentsMargins(0, 0, 0, 0);
    _favoriteLayout->addWidget(_favoriteView);
    
    _favoriteButtonsWidget = new QWidget(_favoriteView);
    _favoriteButtonsLayout = new QHBoxLayout(_favoriteButtonsWidget);
    // _favoriteButtonsLayout->setSpacing(0);
    _favoriteButtonsLayout->setContentsMargins(0,0,0,0);
    _favoriteButtonsWidget->setLayout(_favoriteButtonsLayout);
    
    _addFavoriteButton = new Button("+",this);
    _addFavoriteButton->setMaximumSize(20,20);
    _favoriteButtonsLayout->addWidget(_addFavoriteButton);
    QObject::connect(_addFavoriteButton, SIGNAL(clicked()), this, SLOT(addFavorite()));
    
    _removeFavoriteButton = new Button("-",this);
    _removeFavoriteButton->setMaximumSize(20,20);
    _favoriteButtonsLayout->addWidget(_removeFavoriteButton);
    QObject::connect(_removeFavoriteButton, SIGNAL(clicked()), _favoriteView, SLOT(removeEntry()));
    
    _favoriteButtonsLayout->addStretch();
    
    _favoriteLayout->addWidget(_favoriteButtonsWidget);
    
    
    _centerSplitter->addWidget(_favoriteWidget);
    _centerSplitter->addWidget(_view);
    
    _mainLayout->addWidget(_centerSplitter);
    
    /*creating selection widget*/
    _selectionWidget = new QWidget(this);
    _selectionLayout = new QHBoxLayout(_selectionWidget);
    _selectionLayout->setContentsMargins(0, 0, 0, 0);
    _selectionWidget->setLayout(_selectionLayout);
    
    _sequenceButton = new ComboBox(_buttonsWidget);
    _sequenceButton->addItem("Sequence:");
    _sequenceButton->addItem("File:");
    if(isSequenceDialog){
        _sequenceButton->setCurrentIndex(0);
    }else{
        _sequenceButton->setCurrentIndex(1);
    }
    QObject::connect(_sequenceButton,SIGNAL(currentIndexChanged(QString)),this,SLOT(sequenceComboBoxSlot(QString)));
    _selectionLayout->addWidget(_sequenceButton);
    
    if(!isSequenceDialog){
        _sequenceButton->setVisible(false);
    }
    _selectionLineEdit = new LineEdit(_selectionWidget);
    _selectionLayout->addWidget(_selectionLineEdit);
    
    if(mode==SequenceFileDialog::OPEN_DIALOG)
        _openButton = new Button("Open",_selectionWidget);
    else
        _openButton = new Button("Save",_selectionWidget);
    _selectionLayout->addWidget(_openButton);
    QObject::connect(_openButton, SIGNAL(pressed()), this, SLOT(openSelectedFiles()));
    
    _mainLayout->addWidget(_selectionWidget);
    
    /*creating filter zone*/
    _filterLineWidget = new QWidget(this);
    _filterLineLayout = new QHBoxLayout(_filterLineWidget);
    _filterLineLayout->setContentsMargins(0, 0, 0, 0);
    _filterLineWidget->setLayout(_filterLineLayout);
{'fraction_non_alphanumeric': 0.12110158672259712, 'fraction_numerical': 0.006930512493160679, 'mean_word_length': 4.5574324324324325, 'pattern_counts': {'":': 0, '<': 72, '<?xml version=': 0, '>': 174, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2729151', 'n_tokens_mistral': 5083, 'n_tokens_neox': 4960, 'n_words': 878}