aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/CommandLineOptions/StatusOption
ModeNameSize
-rw-r--r--CMakeLists.txt1355logplainblame
-rw-r--r--StatusOption.pro1159logplainblame
-rw-r--r--statusoption.cpp5504logplainblame
-rw-r--r--statusoption.h2156logplainblame
d---------translations1049logplain
er02@90c681e8-e032-0410-971d-27865f9a5e38> 2019-09-08 11:49:28 +0000 fixed possible regressions' href='/qmmp/commit/src/plugins/General/udisks2/udisks2plugin.cpp?id=463f4e95cff0e100b4c8c8b5378cfe1b2604c138'>463f4e95c
75100e3b8
463f4e95c
75100e3b8
463f4e95c

f8c2616ab
75100e3b8


463f4e95c



75100e3b8




1e31fe896
75100e3b8





f8c2616ab
75100e3b8
f8c2616ab



75100e3b8
f8c2616ab
75100e3b8
75100e3b8




1e31fe896
75100e3b8

f8c2616ab
75100e3b8

75100e3b8
f8c2616ab
ba29477b4
f8c2616ab




75100e3b8
f8c2616ab
75100e3b8







f8c2616ab
75100e3b8
f8c2616ab
75100e3b8


















f8c2616ab

75100e3b8


a65bebd9b
75100e3b8



1e31fe896
75100e3b8


f8c2616ab
75100e3b8











7bdd84eec
75100e3b8



1e31fe896
75100e3b8



b917024aa
75100e3b8



1e31fe896
75100e3b8














b917024aa
75100e3b8



76b31b99f

1e31fe896
75100e3b8
76b31b99f

aa167f22d
75100e3b8






















aa167f22d
76b31b99f
75100e3b8



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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
                                                                            
                                                                            
                                                                            





















                                                                             
























                                                                                                   
                                                                    
                                                  














                                                                     

                                                            
     
                                    
         

                                     
                                                                                  


                            



                 




                                                
                                                                                  





                                                       
                                                             
     



                                                                            
     
        
                      




                                                
                                                          

                         
                                                        

                                                        
         
                                                            
                                                                         




                                                                                    
                                                     
         







                                                
             
                                                                                    
             


















                                                                                          

                                                                                   


                                         
                                                                        



                                                   
                                               


                                
                                                                                                      











                                                                                         
                                                               



                                                           
                                               



                                                  
                   



                                                         
                                                    














                                                        
                   



                                                

                                                                           
                                                                    
     

                           
                                                                         






















                                                                               
                                                                          
                                  



                
/***************************************************************************
 *   Copyright (C) 2013-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 <QtDBus>
#include <QActionGroup>
#include <QApplication>
#include <QStyle>
#include <qmmpui/uihelper.h>
#include <qmmpui/playlistmanager.h>
#include <qmmpui/playlistitem.h>
#include <qmmp/qmmp.h>
#include "udisks2device.h"
#include "udisks2manager.h"
#include "udisks2plugin.h"

UDisks2Plugin::UDisks2Plugin(QObject *parent) : QObject(parent)
{
    qDBusRegisterMetaType<QVariantMapMap>();
    qDBusRegisterMetaType<QByteArrayList>();

    m_manager = new UDisks2Manager(this);
    m_actions = new QActionGroup(this);
    connect(m_manager,SIGNAL(deviceAdded(QDBusObjectPath)), SLOT(addDevice(QDBusObjectPath)));
    connect(m_manager,SIGNAL(deviceRemoved(QDBusObjectPath)), SLOT(removeDevice(QDBusObjectPath)));
    connect(m_actions,SIGNAL(triggered (QAction *)), SLOT(processAction(QAction *)));
    //load settings
    QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
    settings.beginGroup("UDisks2");
    m_detectCDA = settings.value("cda", true).toBool();
    m_detectRemovable = settings.value("removable", true).toBool();
    m_addTracks = false; //do not load tracks on startup
    m_addFiles = false;
    //find existing devices
    const QList<QDBusObjectPath> devs = m_manager->findAllDevices();
    for(const QDBusObjectPath &o : qAsConst(devs))
        addDevice(o);
    //load remaining settings
    m_addTracks = settings.value("add_tracks", false).toBool();
    m_removeTracks = settings.value("remove_tracks", false).toBool();
    m_addFiles = settings.value("add_files", false).toBool();
    m_removeFiles = settings.value("remove_files", false).toBool();
    settings.endGroup();
}

UDisks2Plugin::~UDisks2Plugin()
{
}

void UDisks2Plugin::removeDevice(QDBusObjectPath o)
{
    QList<UDisks2Device *>::iterator it = m_devices.begin();
    while(it != m_devices.end())
    {
        if((*it)->objectPath() == o)
        {
            delete (*it);
            it = m_devices.erase(it);
            qDebug("UDisks2Plugin: removed device: \"%s\"", qPrintable(o.path()));
            updateActions();
            break;
        }
        else
        {
            ++it;
        }
    }
}

void UDisks2Plugin::addDevice(QDBusObjectPath o)
{
    for(const UDisks2Device *device : qAsConst(m_devices)) //is it already exists?
    {
        if (device->objectPath() == o)
            return;
    }
    UDisks2Device *device = new UDisks2Device(o, this);

    if(device->isRemovable()) //detect removable devices only
    {
        qDebug("UDisks2Plugin: added device: \"%s\"", qPrintable(o.path()));
        m_devices << device;
        updateActions();
        connect(device, SIGNAL(changed()), SLOT(updateActions()));
    }
    else
        delete device;
}

void UDisks2Plugin::updateActions()
{
    // add action for cd audio or mounted volume
    for(const UDisks2Device *device : qAsConst(m_devices))
    {
        QString dev_path;
        if (m_detectCDA && device->isAudio()) //cd audio
        {
            dev_path = "cdda://" + device->deviceFile();
        }
        else if (m_detectRemovable && device->isMounted() &&
                 device->property("Size").toLongLong() < 40000000000LL &&
                 (device->property("IdType").toString() == "vfat" ||
                  device->property("IdType").toString() == "iso9660" ||
                  device->property("IdType").toString() == "udf" ||
                  device->property("IdType").toString() == "ext2")) //mounted volume
        {
            dev_path = device->mountPoints().first();
        }
        else
            continue;

        if (!findAction(dev_path))
        {
            QAction *action = new QAction(this);
            QString actionText;
            if (device->isAudio())
            {
                actionText = QString(tr("Add CD \"%1\"")).arg(device->deviceFile());
            }
            else
            {
                QString name = device->property("IdLabel").toString();
                if (name.isEmpty())
                    name = dev_path;

                actionText = QString(tr("Add Volume \"%1\"")).arg(name);
            }

            if (device->isOptical())
            {
                if(device->property("IdType").toString() == "iso9660")
                    action->setIcon(qApp->style()->standardIcon(QStyle::SP_DriveDVDIcon));
                else
                    action->setIcon(qApp->style()->standardIcon(QStyle::SP_DriveCDIcon));
            }
            else
                action->setIcon(qApp->style()->standardIcon(QStyle::SP_DriveHDIcon));

            qDebug("UDisks2Plugin: added menu item: \"%s\"", qPrintable(dev_path));

            action->setText(actionText);
            action->setData(dev_path);
            m_actions->addAction(action);
            UiHelper::instance()->addAction(action, UiHelper::ADD_MENU);
            addPath(dev_path);
        }
    }
    // remove action if device is unmounted/removed
    for(QAction *action : m_actions->actions())
    {
        if (!findDevice(action))
        {
            qDebug("UDisks2Plugin: removed menu item: \"%s\"", qPrintable(action->data().toString()));
            m_actions->removeAction(action);
            UiHelper::instance()->removeAction(action);
            removePath(action->data().toString());
            action->deleteLater();
        }
    }
}

void UDisks2Plugin::processAction(QAction *action)
{
    qDebug("UDisks2Plugin: action triggered: %s", qPrintable(action->data().toString()));
    QString path = action->data().toString();
    PlayListManager::instance()->selectedPlayList()->add(path);
}

QAction *UDisks2Plugin::findAction(const QString &dev_path)