ogs « plugins « src - qmmp - Qmmp with Jyrki's patches
aboutsummaryrefslogblamecommitdiff
path: root/src/plugins/FileDialogs/QmmpFileDialog/qmmpfiledialogimpl.cpp
blob: d21e753fda2d524cddaf7fcaefbd342fe57d6e15 (plain) (tree)
1
2
                                                                           
                                                                           














                                                                           
                                                                           

                                                                            


                               
                       
                    
                 

                      
                      
 

                      



                      
                                                  





                                                                                    
                                                  












                                                                                  
                                                                                               

                  
                                            
                                         
                                           
                               
 
                                    
                                
                                      
                                        
                                                                
                                                      
                                     

                                                                                        


                                                                                               
                                                                                                 
                                       
                                                                                                 

                                                                               
                                                                 
                                                                                                    





                                                                             





                                                                                            
 




                                         
                                                
 



                                                                                           
                                      















                                                                               
                                   
     



                                                  
                
                                                              
               
      
                                                                           
                                                      
                                                                              
                                             
                                                                   













                                                                          
                                                         








                                        



                                                                              
                      

                                                
                         


                                                                


                                                     
                                                         




                                        

                               

         



                                                            


















                                                                                          



                                                   
                  

                                       




                                                                   
                                 



                                                  







                               
     
                                                                                           

                    

 
                                                                                                     
 



                                    
                                     





                                      
     







                                                       

                                     



                                                             
                                   
     

                                                            
     

                                                                             
                                            


        
                                                                               
                                           













                                                                                          

     
                                                       



                                                            
            
     
                                          


     
                                                               
 
            
     
                                          


     






                                                                                     
                                                                 






































                                                                                                        
                                            



                                           
                                                     




                          
                                            



                                  
                                         

























                                                              
                                 




                                              

                                                  
                              





                                                                                   
                                
















                                                                                   


                          


                                                                                           










                                                                                                 
/**************************************************************************
*   Copyright (C) 2008-2016 by Ilya Kotov                                 *
*   forkotov02@hotmail.ru                                                 *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   along with this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
***************************************************************************/

#include "qmmpfiledialogimpl.h"

#include <QDirModel>
#include <QApplication>
#include <QFileInfo>
#include <QStyle>
#include <QSettings>
#include <QMessageBox>
#include <QHeaderView>

#include <qmmp/qmmp.h>

#define HISTORY_SIZE 8


/**
 *   This variable has been copied from Qt library
 */

const char *qt_file_dialog_filter_reg_exp =
    "([a-zA-Z0-9 -]*)\\(([a-zA-Z0-9_.*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$";

/**
 *   This function has been copied from Qt library
 */

// Makes a list of filters from a normal filter string "Image Files (*.png *.jpg)"
static QStringList qt_clean_filter_list(const QString &filter)
{
    QRegExp regexp(QString::fromLatin1(qt_file_dialog_filter_reg_exp));
    QString f = filter;
    int i = regexp.indexIn(f);
    if (i >= 0)
        f = regexp.cap(2);
    return f.split(QLatin1Char(' '), QString::SkipEmptyParts);
}

QmmpFileDialogImpl::QmmpFileDialogImpl(QWidget * parent, Qt::WindowFlags f) : QDialog(parent,f)
{
    setupUi(this);
    setAttribute(Qt::WA_QuitOnClose, false);
    m_model = new QFileSystemModel(this);
    m_model->setNameFilterDisables (false);
    m_model->setReadOnly(true);

    fileListView->setModel(m_model);
    treeView->setModel(m_model);
    treeView->setSortingEnabled(true);
    treeView->setItemsExpandable(false);
    treeView->header()->setSortIndicator(0, Qt::AscendingOrder);
    treeView->header()->setStretchLastSection (false);
    listToolButton->setChecked(true);
    upToolButton->setIcon(qApp->style()->standardIcon(QStyle::SP_ArrowUp));
    listToolButton->setIcon(qApp->style()->standardIcon(QStyle::SP_FileDialogListView));
    closeOnAddToolButton->setIcon(qApp->style()->standardIcon(QStyle::SP_DialogOkButton));
    detailsToolButton->setIcon(qApp->style()->standardIcon(QStyle::SP_FileDialogDetailedView));
    connect(fileListView->selectionModel(),
            SIGNAL(selectionChanged (QItemSelection, QItemSelection)), SLOT(updateSelection ()));
    connect(treeView->selectionModel(),
            SIGNAL(selectionChanged (QItemSelection, QItemSelection)), SLOT(updateSelection ()));
    PathCompleter* completer = new PathCompleter (m_model, fileListView, this);
    fileNameLineEdit->setCompleter (completer);
    QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
    closeOnAddToolButton->setChecked(settings.value("QMMPFileDialog/close_on_add", false).toBool());
    restoreGeometry(settings.value("QMMPFileDialog/geometry").toByteArray());
    m_history = settings.value("QMMPFileDialog/history").toStringList();
    lookInComboBox->addItems(m_history);
    lookInComboBox->setMaxCount(HISTORY_SIZE);
    QCompleter* dir_completer = new QCompleter (m_model, this);
    lookInComboBox->setCompleter (dir_completer);

    if(qApp->style()->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons, 0, this))
    {
        addPushButton->setIcon(qApp->style()->standardIcon(QStyle::SP_DialogOpenButton));
        closePushButton->setIcon(qApp->style()->standardIcon(QStyle::SP_DialogCloseButton));
    }
}

QmmpFileDialogImpl::~QmmpFileDialogImpl()
{
}

QStringList QmmpFileDialogImpl::selectedFiles ()
{
    QStringList l;
    if (m_mode == FileDialog::SaveFile)
    {
        l << m_model->filePath(fileListView->rootIndex()) + "/" + fileNameLineEdit->text();
        qDebug("%s",qPrintable(l[0]));
    }
    else
    {
        QModelIndexList ml = fileListView->selectionModel()->selectedIndexes();
        foreach(QModelIndex i,ml)
        l << m_model->filePath(i);
    }
    return l;
}

void QmmpFileDialogImpl::on_lookInComboBox_activated(const QString &path)
{
    if (QDir(path).exists ())
    {