aboutsummaryrefslogblamecommitdiff
path: root/src/plugins/Ui/skinned/skinnedfactory.cpp
blob: d43ffbd5608ce908b9fd60e329babee86a4e3241 (plain) (tree)
1
2
                                                                            
                                                                            














                                                                            
                                                                            
                                                                             
 
                   
                      
                              

                           
 
                                                     
 
                       


                                              
                 

 
                                                 
 
                                                                      
                            

 



                                                                        
                                                                                               





                                                                             

 

                                                              
 



                                                            
 

                                         
/***************************************************************************
 *   Copyright (C) 2011-2015 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 <QtPlugin>
#include <QMessageBox>
#include <qmmp/qmmpsettings.h>
#include "mainwindow.h"
#include "skinnedfactory.h"

const UiProperties SkinnedFactory::properties() const
{
    UiProperties props;
    props.hasAbout = true;
    props.name = tr("Skinned User Interface");
    props.shortName = "skinned";
    return props;
}

QObject *SkinnedFactory::SkinnedFactory::create()
{
    QmmpSettings::instance()->readEqSettings(EqSettings::EQ_BANDS_10);
    return new MainWindow();
}

void SkinnedFactory::showAbout(QWidget *parent)
{
    QMessageBox::about (parent, tr("About Qmmp Skinned User Interface"),
                        tr("Qmmp Skinned User Interface")+"\n"+
                        tr("Simple user interface with Winamp-2.x/XMMS skins support") + "\n" +
                        tr("Written by:")+"\n"+
                        tr("Vladimir Kuznetsov <vovanec@gmail.com>")+"\n"+
                        tr("Ilya Kotov <forkotov02@hotmail.ru>")+"\n"+
                        tr("Artwork:")+"\n"+
                        tr("Andrey Adreev <andreev00@gmail.com>")+"\n"+
                        tr("sixixfive <http://sixsixfive.deviantart.com/>"));

}

QTranslator *SkinnedFactory::createTranslator(QObject *parent)
{
    QTranslator *translator = new QTranslator(parent);
    QString locale = Qmmp::systemLanguageID();
    translator->load(QString(":/skinned_plugin_") + locale);
    return translator;
}

Q_EXPORT_PLUGIN2(skinned, SkinnedFactory)
-e032-0410-971d-27865f9a5e38> 2011-07-12 17:45:06 +0000 added configuration dialog' href='/qmmp/commit/src/plugins/Ui/skinned/skinnedsettings.cpp?id=4cb1b12751e486cea156c94c826c693fcf3d2f47'>4cb1b1275
6d7605eb3
5aad2ffd2
4cb1b1275


6d7605eb3
4cb1b1275
4cb1b1275
50f2091ac
299214e2a
4cb1b1275

d3e68ec37
4cb1b1275





6d7605eb3
4cb1b1275
6d7605eb3







4cb1b1275









12fefde04
2731ececc

12fefde04
2731ececc
35b039d6d
2731ececc

4cb1b1275




6d7605eb3
da552eeaf


6d7605eb3

35b039d6d

6d7605eb3
11f96a1f8
6d7605eb3
4cb1b1275
6d7605eb3


4cb1b1275
6d7605eb3
5aad2ffd2
6d7605eb3

034128b6d
4cb1b1275






6d7605eb3

da552eeaf
6d7605eb3


35b039d6d

6d7605eb3







4cb1b1275
6d7605eb3

2731ececc
01e8d2286


4cb1b1275

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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
                                                                            
                                                                            
                                                                            













                                                                            
                                                                            






                                                                             
                            
                                         






                                                                   

                                                  

                                    
                                                                          


                   
                    
                 


                                                                     






                                                                  
                                            








                                                                      
                                                           
     

                                                                   






                                               
                                          


                                                  

                                                                                              


     








                                                                                                  


     


                                                 
                                            


                                                  

                                                                                                


     








                                                                  






                                                                                                                   
                                                                              



                

                                             

                                                                                    

 

                                 
               
                                                                  


                                                                                              

                                                                                          
 
                                                                                             





                                                                                              

                                                                                            
 
                                                                                              
















                                                                                 
                                            




                                   

                                     
                                                                                                     
                                          
                                                                    
                                                                                         

 



                                 
                             
                                   


                                                                           
                                    
                           
 
                                            
                                              

                                                   
                                





                                                                            
                                        
                                      







                                                                           









                                                      
                                                              

                                                        
                                              
        
                                                      

 




                                                                  
                                                                                           


                                                                                       

                                                                                           

                                                                                                             
                                                                                    
                                                                                 
                                                                                                
                  


                                                                                                
          
                                                                                         
                                                                        

                                                                                          
                                                                                                             






                                                                  

                                                                               
                                                                             


                                                                                

                                                                                                  







                                                                                            
                                                       

                                                                               
                                                                                


                                                                                  

                        
/***************************************************************************
 *   Copyright (C) 2011-2019 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 <QSettings>
#include <QDir>
#include <QFontDialog>
#include <qmmp/qmmp.h>
#include <qmmpui/filedialog.h>
#include <qmmpui/uihelper.h>
#include <qmmpui/metadataformattermenu.h>
#include "skinreader.h"
#include "skin.h"
#include "popupsettings.h"
#include "skinnedsettings.h"

SkinnedSettings::SkinnedSettings(QWidget *parent) : QWidget(parent)
{
    m_ui.setupUi(this);
    m_ui.listWidget->setIconSize (QSize (105,34));
    m_skin = Skin::instance();
    m_reader = new SkinReader(this);
    connect(m_ui.skinReloadButton, SIGNAL (clicked()), SLOT(loadSkins()));
    readSettings();
    loadSkins();
    loadFonts();
    createActions();
    //setup icons
    m_ui.skinInstallButton->setIcon(QIcon::fromTheme("list-add"));
    m_ui.skinReloadButton->setIcon(QIcon::fromTheme("view-refresh"));
    m_ui.popupTemplateButton->setIcon(QIcon::fromTheme("configure"));
}

SkinnedSettings::~SkinnedSettings()
{}

void SkinnedSettings::on_listWidget_itemClicked(QListWidgetItem *)
{
    int row = m_ui.listWidget->currentRow();
    QString path;
    if (m_skinList.at (row).isDir())
    {
        path = m_skinList.at (row).canonicalFilePath();
        m_skin->setSkin (path);
    }
    else if (m_skinList.at (row).isFile())
    {
        m_reader->unpackSkin(m_skinList.at (row).canonicalFilePath());
        m_skin->setSkin(Qmmp::configDir() + "/cache/skin");
    }
    if(m_ui.listWidget->currentItem())
        m_currentSkinName = m_ui.listWidget->currentItem()->text();
    else
        m_currentSkinName.clear();
}

void SkinnedSettings::on_plFontButton_clicked()
{
    bool ok;
    QFont font = m_ui.plFontLabel->font();
    font = QFontDialog::getFont (&ok, font, this);
    if (ok)
    {
        m_ui.plFontLabel->setText (font.family () + " " + QString::number(font.pointSize ()));
        m_ui.plFontLabel->setFont(font);
    }
}

void SkinnedSettings::on_headerFontButton_clicked()
{
    bool ok;
    QFont font = m_ui.plFontLabel->font();
    font = QFontDialog::getFont (&ok, font, this);
    if (ok)
    {
        m_ui.headerFontLabel->setText (font.family () + " " + QString::number(font.pointSize ()));
        m_ui.headerFontLabel->setFont(font);
    }
}

void SkinnedSettings::on_mainFontButton_clicked()
{
    bool ok;
    QFont font = m_ui.mainFontLabel->font();
    font = QFontDialog::getFont (&ok, font, this);
    if (ok)
    {
        m_ui.mainFontLabel->setText (font.family () + " " + QString::number(font.pointSize ()));
        m_ui.mainFontLabel->setFont(font);
    }
}

void SkinnedSettings::on_resetFontsButton_clicked()
{
    QSettings settings (Qmmp::configFile(), QSettings::IniFormat);
    settings.remove("Skinned/pl_font");
    settings.remove("Skinned/pl_header_font");
    settings.remove("Skinned/mw_font");
    loadFonts();
}

void SkinnedSettings::on_skinInstallButton_clicked()
{
    QStringList files = FileDialog::getOpenFileNames(this,tr("Select Skin Files"), QDir::homePath(),
                                                     tr("Skin files") + " (*.tar.gz *.tgz *.tar.bz2 *.zip *.wsz)");
    foreach(QString path, files)
    {
        QFile file(path);
        file.copy(Qmmp::configDir() + "/skins/" + QFileInfo(path).fileName());
    }
    loadSkins();
}

void SkinnedSettings::showEvent(QShowEvent *)
{
    m_ui.hiddenCheckBox->setEnabled(UiHelper::instance()->visibilityControl());
    m_ui.hideOnCloseCheckBox->setEnabled(UiHelper::instance()->visibilityControl());
}

void SkinnedSettings::loadFonts()
{
    QFont font;
    QSettings settings (Qmmp::configFile(), QSettings::IniFormat);

    QString fontname = settings.value ("Skinned/pl_font", qApp->font().toString()).toString();
    font.fromString(fontname);
    m_ui.plFontLabel->setText (font.family () + " " + QString::number(font.pointSize ()));
    m_ui.plFontLabel->setFont(font);

    fontname = settings.value ("Skinned/pl_header_font", qApp->font().toString()).toString();
    font.fromString(fontname);
    m_ui.headerFontLabel->setText (font.family () + " " + QString::number(font.pointSize ()));
    m_ui.headerFontLabel->setFont(font);

    fontname = settings.value ("Skinned/mw_font", qApp->font().toString()).toString();
    font.fromString(fontname);
    m_ui.mainFontLabel->setText (font.family () + " " + QString::number(font.pointSize ()));
    m_ui.mainFontLabel->setFont(font);

    m_ui.useBitmapCheckBox->setChecked(settings.value("Skinned/bitmap_font", false).toBool());
}

void SkinnedSettings::findSkins(const QString &path)
{
    QDir dir(path);
    dir.setFilter (QDir::Dirs | QDir::NoDotAndDotDot);
    QList <QFileInfo> fileList = dir.entryInfoList();
    if (fileList.count() == 0)
        return;
    foreach (QFileInfo fileInfo, fileList)
    {
        QPixmap preview = Skin::getPixmap ("main", QDir(fileInfo.filePath ()));
        if (!preview.isNull())
        {
            QListWidgetItem *item = new QListWidgetItem (fileInfo.fileName ());
            item->setIcon (preview);
            item->setToolTip(tr("Unarchived skin") + " " + fileInfo.filePath ());
            m_ui.listWidget->addItem (item);
            m_skinList << fileInfo;
        }
    }
}

void SkinnedSettings::createActions()
{
    MetaDataFormatterMenu *menu = new MetaDataFormatterMenu(MetaDataFormatterMenu::TITLE_MENU, this);
    m_ui.windowTitleButton->setMenu(menu);
    m_ui.windowTitleButton->setPopupMode(QToolButton::InstantPopup);
    connect(menu, SIGNAL(patternSelected(QString)), SLOT(addWindowTitleString(QString)));
}

void SkinnedSettings::loadSkins()
{
    m_reader->generateThumbs();
    m_skinList.clear();
    m_ui.listWidget->clear();
    QFileInfo fileInfo (":/glare");
    QPixmap preview = Skin::getPixmap ("main", QDir (fileInfo.filePath()));
    QListWidgetItem *item = new QListWidgetItem (fileInfo.fileName ());
    item->setIcon (preview);
    m_ui.listWidget->addItem (item);
    m_skinList << fileInfo;

    findSkins(Qmmp::configDir() + "/skins");
#if defined(Q_OS_WIN) && !defined(Q_OS_CYGWIN)
    findSkins(qApp->applicationDirPath()+"/skins");
#else
    findSkins(Qmmp::dataPath());
#endif
    foreach(QString path, m_reader->skins())
    {
        QListWidgetItem *item = new QListWidgetItem (path.section('/', -1));
        item->setIcon (m_reader->getPreview(path));
        item->setToolTip(tr("Archived skin") + " " + path);
        m_ui.listWidget->addItem (item);
        m_skinList << QFileInfo(path);
    }
    for(int i = 0; i < m_ui.listWidget->count(); ++i)
    {
        if(m_ui.listWidget->item(i)->text() == m_currentSkinName)
        {
            m_ui.listWidget->setCurrentRow(i, QItemSelectionModel::Select);
            break;
        }
    }
}

void SkinnedSettings::on_popupTemplateButton_clicked()
{
    PopupSettings *p = new PopupSettings(this);
    p->exec();
    p->deleteLater();
}

void SkinnedSettings::addWindowTitleString(const QString &str)
{
    if (m_ui.windowTitleLineEdit->cursorPosition () < 1)
        m_ui.windowTitleLineEdit->insert(str);
    else
        m_ui.windowTitleLineEdit->insert(" - " + str);
}

void SkinnedSettings::readSettings()
{
    QSettings settings (Qmmp::configFile(), QSettings::IniFormat);
    settings.beginGroup("Skinned");
    //playlist
    m_ui.protocolCheckBox->setChecked(settings.value ("pl_show_protocol", false).toBool());
    m_ui.numbersCheckBox->setChecked(settings.value("pl_show_numbers", true).toBool());
    m_ui.lengthsCheckBox->setChecked(settings.value("pl_show_lengths", true).toBool());
    m_ui.alignCheckBox->setChecked(settings.value("pl_align_numbers", false).toBool());
    m_ui.anchorCheckBox->setChecked(settings.value("pl_show_anchor", false).toBool());
    m_ui.playlistsCheckBox->setChecked(settings.value("pl_show_plalists", false).toBool());
    m_ui.showSplittersCheckBox->setChecked(settings.value("pl_show_splitters", true).toBool());
    m_ui.alternateSplitterColorCheckBox->setChecked(settings.value("pl_alt_splitter_color", false).toBool());
    m_ui.popupCheckBox->setChecked(settings.value("pl_show_popup", false).toBool());
    m_ui.plSeplineEdit->setText(settings.value("pl_separator", "::").toString());
    m_ui.showNewPLCheckBox->setChecked(settings.value("pl_show_create_button", false).toBool());
    //transparency
    m_ui.mwTransparencySlider->setValue(100 - settings.value("mw_opacity", 1.0).toDouble()*100);
    m_ui.eqTransparencySlider->setValue(100 - settings.value("eq_opacity", 1.0).toDouble()*100);
    m_ui.plTransparencySlider->setValue(100 - settings.value("pl_opacity", 1.0).toDouble()*100);
    //view
    m_ui.skinCursorsCheckBox->setChecked(settings.value("skin_cursors", false).toBool());
    m_currentSkinName = settings.value("skin_name", "glare").toString();
    m_ui.hiddenCheckBox->setChecked(settings.value("start_hidden", false).toBool());
    m_ui.hideOnCloseCheckBox->setChecked(settings.value("hide_on_close", false).toBool());
    m_ui.windowTitleLineEdit->setText(settings.value("window_title_format","%if(%p,%p - %t,%t)").toString());
    settings.endGroup();
}

void SkinnedSettings::writeSettings()
{
    QSettings settings (Qmmp::configFile(), QSettings::IniFormat);
    settings.beginGroup("Skinned");
    settings.setValue ("pl_show_protocol", m_ui.protocolCheckBox->isChecked());
    settings.setValue ("pl_show_numbers", m_ui.numbersCheckBox->isChecked());
    settings.setValue ("pl_show_lengths", m_ui.lengthsCheckBox->isChecked());
    settings.setValue ("pl_align_numbers", m_ui.alignCheckBox->isChecked());
    settings.setValue ("pl_show_anchor", m_ui.anchorCheckBox->isChecked());
    settings.setValue ("pl_show_plalists", m_ui.playlistsCheckBox->isChecked());
    settings.setValue ("pl_show_splitters", m_ui.showSplittersCheckBox->isChecked());
    settings.setValue ("pl_alt_splitter_color", m_ui.alternateSplitterColorCheckBox->isChecked());
    settings.setValue ("pl_show_popup", m_ui.popupCheckBox->isChecked());
    settings.setValue ("pl_separator", m_ui.plSeplineEdit->text());
    settings.setValue ("pl_show_create_button", m_ui.showNewPLCheckBox->isChecked());
    settings.setValue ("mw_opacity", 1.0 -  (double)m_ui.mwTransparencySlider->value()/100);
    settings.setValue ("eq_opacity", 1.0 -  (double)m_ui.eqTransparencySlider->value()/100);
    settings.setValue ("pl_opacity", 1.0 -  (double)m_ui.plTransparencySlider->value()/100);
    settings.setValue ("bitmap_font", m_ui.useBitmapCheckBox->isChecked());
    settings.setValue ("skin_cursors", m_ui.skinCursorsCheckBox->isChecked());
    settings.setValue ("skin_name", m_currentSkinName);
    settings.setValue ("start_hidden", m_ui.hiddenCheckBox->isChecked());
    settings.setValue ("hide_on_close", m_ui.hideOnCloseCheckBox->isChecked());
    settings.setValue ("window_title_format", m_ui.windowTitleLineEdit->text());
    settings.setValue ("mw_font", m_ui.mainFontLabel->font().toString());
    settings.setValue ("pl_font", m_ui.plFontLabel->font().toString());
    settings.setValue ("pl_header_font", m_ui.headerFontLabel->font().toString());
    settings.endGroup();
}