aboutsummaryrefslogtreecommitdiff
path: root/src
ModeNameSize
d---------app593logplain
d---------plugins510logplain
d---------qmmp3196logplain
d---------qmmpui4094logplain
le='author trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> 2008-07-09 18:54:22 +0000 committer trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> 2008-07-09 18:54:22 +0000 completed file dialog support' href='/qmmp/commit/src/qmmpui/filedialog.cpp?id=e85b77286f66edecdc3707065e39b31f2e220f5a'>e85b77286
a8bf072ec
e85b77286

be65205e6
6f1f9ca43
e85b77286
6f1f9ca43

e85b77286
be65205e6
ae75e5707
d8073e08b
be65205e6
6ba4fc48f
6f1f9ca43
c88e5e9cf

d8073e08b
c88e5e9cf
6f1f9ca43
d8073e08b
6f1f9ca43
d8073e08b
c88e5e9cf
6f1f9ca43
d8073e08b



025866f86

38bfcb867


6f1f9ca43
d8073e08b

e85b77286
d8073e08b

e85b77286
d8073e08b
6f1f9ca43


d8073e08b
6f1f9ca43
d8073e08b







6f1f9ca43

c88e5e9cf
6f1f9ca43
d8073e08b
ae75e5707
c88e5e9cf

6f1f9ca43
c88e5e9cf

d8073e08b
c88e5e9cf



e85b77286
c88e5e9cf

d8073e08b






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
c88e5e9cf



d8073e08b
c88e5e9cf
d8073e08b
c88e5e9cf
d8073e08b
c88e5e9cf




d8073e08b
c88e5e9cf














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
230
231
232
233
234
235
236
237
238
239
                                                                           
                                                                           
                                                                           













                                                                           
                                                                           

                                                                            
                
                    
                      

                        
                      
                   
                      
                                
                       
                           
 

                                       
                                                   
                                                    
 
                              
 
                
               
 



                                                                    

                                          


                                                                          
     

                                                                                                          
         

                        
         
                              


     
                                                  
 







                                                   

 
                                                       
 
                  
                                                                  

                                                                     
 

                                                      
                  



                                                                        
 

                                                    






                                                                
 
 



                                                         

                                                                               
 
 





                                                            

                                                                                                       

 


                                                                                 
 
                                                                                                

 


                                                                               
 

                                                                                                         

 






                                              
 
 

                                                     
                                  

                                      
                                              



                                                           
                                                                                     



                                                                                      





                                                                       
                                                                                    
     

 

                                  
                  



                                                                        
                                              
     
                                     
         
                                                 




                  
                                                       














                                                  















                                                                                                      






                                                                          
                                                                                 
                                                                                           


                             
 
                                                       
 






                                                       
 
/**************************************************************************
*   Copyright (C) 2008-2016 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 <QTranslator>
#include <QApplication>
#include <QPluginLoader>
#include <QMetaObject>
#include <QLibrary>
#include <qmmp/qmmp.h>
#include "qmmpuiplugincache_p.h"
#include "filedialog.h"
#include "qtfiledialog_p.h"

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

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);
    QDir pluginsDir (Qmmp::pluginsPath());
    pluginsDir.cd("FileDialogs");
    QStringList filters;
    filters << "*.dll" << "*.so";
    foreach (QString fileName, pluginsDir.entryList(filters, QDir::Files))
    {
        QmmpUiPluginCache *item = new QmmpUiPluginCache(pluginsDir.absoluteFilePath(fileName), &settings);
        if(item->hasError())
        {
            delete item;
            continue;
        }
        m_cache->append(item);
    }
}

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

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

bool FileDialog::isEnabled(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(FileDialogFactory *factory)
{
    loadPlugins();
    foreach(QmmpUiPluginCache *item, *m_cache)
    {
        if(item->shortName() == factory->properties().shortName)
            return item->file();
    }
    return QString();
}

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();