aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/General
Commit message (Expand)AuthorAgeFilesLines
* updated .ts filestrialuser022015-06-1626-26/+26
* fixed typotrialuser022015-06-161-1/+1
* update Ukrainian translationmotsyo2015-06-161-1/+1
* updated Russian translationtrialuser022015-06-161-1/+1
* updated .ts filestrialuser022015-06-1626-364/+546
* rgscan: fixed regressiontrialuser022015-06-161-2/+5
* rgscan: added feature to detect previous tags (#709)trialuser022015-06-154-29/+76
* updated Ukrainian translationsmotsyo2015-06-131-8/+8
* fixed Russian translationtrialuser022015-06-121-1/+1
* updated Russian translationtrialuser022015-06-121-8/+8
* updated .ts filestrialuser022015-06-1226-26/+26
* fixed typotrialuser022015-06-121-1/+1
* updated .ts filestrialuser022015-06-1226-650/+650
* fileops: improved settings dialogtrialuser022015-06-123-24/+52
* updated .ts filestrialuser022015-06-1126-712/+1546
* fileops: refactoringtrialuser022015-06-112-151/+180
* fileops: added feature to move files (#132)trialuser022015-06-113-14/+118
* refactoringtrialuser022015-06-112-58/+55
* updated Portuguese translation (Sérgio Marques)trialuser022015-06-101-1/+1
* updated German translation (Ettore Atalan)trialuser022015-06-102-7/+7
* update Ukrainian translationsmotsyo2015-06-091-1/+1
* scrobbler: fixed libre.fm supporttrialuser022015-05-273-10/+10
* updated Russian translationtrialuser022015-05-251-1/+1
* updated .ts filestrialuser022015-05-2526-44/+44
* fixed English localizationtrialuser022015-05-251-1/+1
* prepare for Greek translationtrialuser022015-05-2336-0/+2134
* updated German translation (Ettore Atalan)trialuser022015-05-102-13/+13
* updated Portuguese translation (Sérgio Marques)trialuser022015-05-103-19/+19
* fixed rgscan buildtrialuser022015-05-091-1/+1
* update Ukrainian translationmotsyo2015-05-091-6/+6
* updated Russian translationtrialuser022015-05-091-1/+1
* updated .ts filestrialuser022015-05-0925-130/+130
* fixed localizationtrialuser022015-05-091-1/+1
* updated .ts filestrialuser022015-05-0925-552/+677
* updated track change plugintrialuser022015-05-091-6/+7
* updated Russian translationtrialuser022015-05-092-13/+13
* updated Ukrainian translationsmotsyo2015-05-092-13/+13
* updated .ts filestrialuser022015-05-0650-1321/+1696
* chaned localizationtrialuser022015-05-061-1/+1
* updated other dialogstrialuser022015-05-063-57/+60
* updated German translation (Ettore Atalan)trialuser022015-04-2918-337/+337
* prepare for Bulgarian translationtrialuser022015-04-0336-0/+2114
* fixed win32 buildtrialuser022015-03-141-1/+1
* updated Hebrew translation (Genghis Khan)trialuser022015-03-0918-84/+79
* updated Czech translation (Jaroslav Lichtblau)trialuser022015-03-0914-207/+206
* updated .ts filestrialuser022015-03-0972-192/+192
* reduced number of template compilationtrialuser022015-02-022-16/+6
* optimizationtrialuser022015-02-022-6/+6
* enabled new metadata formattertrialuser022015-02-0210-22/+21
* renaming experimental branchtrialuser022015-01-0939-432/+44
<vovanec@90c681e8-e032-0410-971d-27865f9a5e38> 2007-07-24 16:05:25 +0000 committer vovanec <vovanec@90c681e8-e032-0410-971d-27865f9a5e38> 2007-07-24 16:05:25 +0000 added filedialog interface, fixed plugin paths' href='/qmmp/commit/src/filedialog.cpp?id=6f1f9ca43a8773cdfb5e3a7d72fda79c4a442016'>6f1f9ca43
d8073e08b
ae75e5707
c88e5e9cf

6f1f9ca43
e3c013c70
c88e5e9cf
d8073e08b
c88e5e9cf



e85b77286
e3c013c70
c88e5e9cf
d8073e08b
6cf6bc2f6


c88e5e9cf
6f1f9ca43
c88e5e9cf



6881ea9bb

c88e5e9cf
6f1f9ca43
c88e5e9cf





6881ea9bb

6f1f9ca43

c88e5e9cf


6f1f9ca43
6881ea9bb
6f1f9ca43

c88e5e9cf


6f1f9ca43
6881ea9bb

6f1f9ca43

e85b77286






6f1f9ca43
6f1f9ca43
e85b77286

c2a415452
e85b77286

c88e5e9cf
e85b77286



d9ebb4657
025866f86



e85b77286





e2ea8990c
e85b77286
6f1f9ca43

c88e5e9cf

d8073e08b
b917024aa
c88e5e9cf


6cf6bc2f6




c88e5e9cf

d8073e08b
c88e5e9cf






b917024aa
c88e5e9cf






c88e5e9cf


b917024aa
c88e5e9cf











c88e5e9cf






912dd0717
5b7ac8f93
c88e5e9cf


6f1f9ca43
e85b77286
6f1f9ca43
e85b77286






6f1f9ca43
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
                                                                           
                                                                           
                                                                           













                                                                           
                                                                           

                                                                            
                
                    

                        
                      
                   
                    
                      
                                
                       
                           
 
                  


                                                          
 
                              
 
                
               
 



                                                                    
                                                                   
     
                                                                             
                            
         

                        
         
                              


     
                                                  
 

                                    
                                                     




                                                   

 
                                                             
 
                  
                                                                  

                                                                     
 
                                                            
 
                  



                                                                        
 
                                                          
 
                  


                                                                                                                                 
 
 



                                                         

                                                                               
 
 





                                                            

                                                                                                       

 


                                                                                 
 
                                                                                                

 


                                                                               
 

                                                                                                         

 






                                              
 
 

                                                     
                                  

                                      
                                              



                                                           
                                                                                     



                                                                                      





                                                                       
                                                                                    
     

 

                                  
                  
                                          


                                                                        




                                                                                                   

                 
                                                       






                                                  
                             






                                            


                                                          
                        











                                                                                                      






                                                                          
                                                                                 
                                                                                           


                             
 
                                                       
 






                                                       
 
/**************************************************************************
*   Copyright (C) 2008-2021 by Ilya Kotov                                 *
*   forkotov02@ya.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 <QFile>
#include <QSettings>
#include <QApplication>
#include <QPluginLoader>
#include <QMetaObject>
#include <QLibrary>
#include <algorithm>
#include <qmmp/qmmp.h>
#include "qmmpuiplugincache_p.h"
#include "filedialog.h"
#include "qtfiledialog_p.h"

//static functions
FileDialog* FileDialog::m_instance = nullptr;
QList<QmmpUiPluginCache*> *FileDialog::m_cache = nullptr;
FileDialogFactory *FileDialog::m_currentFactory = nullptr;

void FileDialog::loadPlugins()
{
    if (m_cache)
        return;

    m_cache = new QList<QmmpUiPluginCache*>;
    m_cache->append(new QmmpUiPluginCache(new QtFileDialogFactory));

    QSettings settings (Qmmp::configFile(), QSettings::IniFormat);
    for(const QString &filePath : Qmmp::findPlugins("FileDialogs"))
    {
        QmmpUiPluginCache *item = new QmmpUiPluginCache(filePath, &settings);
        if(item->hasError())
        {
            delete item;
            continue;
        }
        m_cache->append(item);
    }
}

QList<FileDialogFactory *> FileDialog::factories()
{
    loadPlugins();
    QList<FileDialogFactory *> list;
    for(QmmpUiPluginCache *item : qAsConst(*m_cache))
    {
        if(item->fileDialogFactory())
            list.append(item->fileDialogFactory());
    }
    return list;
}

void FileDialog::setEnabled(const FileDialogFactory *factory)
{
    loadPlugins();
    QSettings settings (Qmmp::configFile(), QSettings::IniFormat);
    settings.setValue("FileDialog", factory->properties().shortName);
}

bool FileDialog::isEnabled(const FileDialogFactory *factory)
{
    loadPlugins();
    QSettings settings (Qmmp::configFile(), QSettings::IniFormat);
    QString name = settings.value("FileDialog", "qt_dialog").toString();
    return factory->properties().shortName == name;
}

QString FileDialog::file(const FileDialogFactory *factory)
{
    loadPlugins();
    auto it = std::find_if(m_cache->cbegin(), m_cache->cend(),
                           [factory] (QmmpUiPluginCache *item){ return item->shortName() == factory->properties().shortName; } );
    return it == m_cache->cend() ? QString() : (*it)->file();
}

QString FileDialog::getExistingDirectory(QWidget *parent,
        const QString &caption,
        const QString &dir)
{
    QStringList l = instance()->exec(parent, dir, FileDialog::AddDir, caption);
    return l.isEmpty() ? QString() : l.at(0);
}

QString FileDialog::getOpenFileName(QWidget *parent,
                                    const QString &caption,
                                    const QString &dir,
                                    const QString &filter,
                                    QString *selectedFilter)
{
   QStringList l = instance()->exec(parent, dir, FileDialog::AddFile, caption, filter, selectedFilter);
   return l.isEmpty() ? QString() : l.at(0);
}

QStringList FileDialog::getOpenFileNames(QWidget *parent, const QString &caption,
        const QString &dir,const QString &filter,
        QString *selectedFilter)
{
    return instance()->exec(parent, dir, FileDialog::AddFiles, caption, filter, selectedFilter);
}

QString FileDialog::getSaveFileName (QWidget *parent, const QString &caption,
                                     const QString& dir, const QString &filter,
                                     QString *selectedFilter)
{
    QStringList l = instance()->exec(parent, dir, FileDialog::SaveFile, caption, filter, selectedFilter);
    return l.isEmpty() ? QString() : l.at(0);
}

void FileDialog::popup(QWidget *parent,
                       Mode m,
                       QString *dir,
                       QObject *receiver,
                       const char *member,
                       const QString &caption,
                       const QString &filters)

{
    if (!dir)
        qFatal("FileDialog: empty last dir pointer");
    FileDialog* inst = instance();
    inst->setParent(parent);
    inst->init(receiver, member, dir);
    if (!m_currentFactory->properties().modal)
        inst->raise(*dir, m, caption, filters.split(";;"));
    else
    {
        QStringList files;
        if (m == AddFiles || m == AddFile || m == AddDirsFiles || m == PlayDirsFiles)
        {
            QString selectedFilter;
            files = getOpenFileNames(parent, caption, *dir, filters, &selectedFilter);
        }
        else if (m == AddDirs || m == AddDir)
        {
            QString path = getExistingDirectory(parent, caption, *dir);
            if (!path.isEmpty())
                files << path;
        }
        QMetaObject::invokeMethod(inst, "filesSelected", Q_ARG(QStringList, files));
    }
}

FileDialog* FileDialog::instance()
{
    loadPlugins();
    FileDialogFactory *selected = nullptr;

    QSettings settings (Qmmp::configFile(), QSettings::IniFormat);
    QString name = settings.value("FileDialog", "qt_dialog").toString();

    auto it = std::find_if(m_cache->cbegin(), m_cache->cend(),
                           [name] (QmmpUiPluginCache *item){ return item->shortName() == name; } );
    if(it != m_cache->cend())
        selected = (*it)->fileDialogFactory();

    if(!selected)
        selected = m_cache->at(0)->fileDialogFactory();

    if(selected == m_currentFactory && m_instance)
        return m_instance;

    if(m_instance)
    {
        delete m_instance;
        m_instance = nullptr;
    }

    m_currentFactory = selected;
    m_instance = m_currentFactory->create();
    return m_instance;
}

//base implementation
FileDialog::FileDialog() : QObject(), m_initialized(false)
{
    m_lastDir = nullptr;
}

FileDialog::~FileDialog() {}

void FileDialog::raise(const QString &dir, Mode mode, const QString &caption, const QStringList &mask)
{
    Q_UNUSED(dir);
    Q_UNUSED(mode);
    Q_UNUSED(caption);
    Q_UNUSED(mask);
}

void FileDialog::init(QObject* receiver, const char* member, QString *dir)
{
    m_lastDir = dir;
    if (m_initialized)
        disconnect();
    if (receiver &&  member)
    {
        connect(this,SIGNAL(filesSelected(QStringList, bool)), receiver, member);
        connect(this,SIGNAL(filesSelected(QStringList)), SLOT(updateLastDir(QStringList)));
        m_initialized = true;
    }
}

void FileDialog::updateLastDir(const QStringList& list)
{
    if (!list.isEmpty() && m_lastDir)
    {
        QString path = list[0];
        if (path.endsWith('/'))
            path.remove(path.size()-1, 1);
        *m_lastDir = path.left(path.lastIndexOf ('/'));
    }
}