OTHER: Add SkinManager class
Now Skin no longer is a singleton class. In the long run, Skin will only hold information about a skin, while SkinManager will be responsible for loading skins and notifying the windows of the change
This commit is contained in:
parent
23749446fa
commit
ebbcea80b9
20 changed files with 296 additions and 137 deletions
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* This file is a part of Promoe, an XMMS2 Client.
|
||||
*
|
||||
* Copyright (C) 2005-2008 XMMS2 Team
|
||||
* Copyright (C) 2005-2010 XMMS2 Team
|
||||
*
|
||||
* 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
|
||||
|
|
@ -19,28 +19,39 @@
|
|||
#include <QPainter>
|
||||
#include <QSettings>
|
||||
|
||||
static const QString defaultSkin = ":/skins/Almond-blue/";
|
||||
|
||||
Skin *Skin::singleton = NULL;
|
||||
|
||||
Skin *Skin::getInstance (void)
|
||||
{
|
||||
if (!singleton) {
|
||||
singleton = new Skin ();
|
||||
}
|
||||
|
||||
return singleton;
|
||||
}
|
||||
|
||||
Skin::Skin ()
|
||||
Skin::Skin (const QString &url)
|
||||
{
|
||||
setSizes ();
|
||||
setPositions ();
|
||||
|
||||
QSettings settings;
|
||||
setSkin (settings.value("skin/path", defaultSkin).toString ());
|
||||
m_valid = setSkin (url);
|
||||
}
|
||||
|
||||
// Copy string and replace data with that from url.
|
||||
Skin::Skin (Skin *other, const QString &url)
|
||||
{
|
||||
Q_ASSERT (other != 0);
|
||||
|
||||
m_sizes = other->m_sizes;
|
||||
m_positions = other->m_positions;
|
||||
|
||||
// At the moment, these are only used if url == "", but
|
||||
// later windows that aren't modified in a skin should be displayed
|
||||
// with the default skin
|
||||
m_items = other->m_items;
|
||||
m_letterMap = other->m_letterMap;
|
||||
m_smallNumbers = other->m_smallNumbers;
|
||||
m_numbers = other->m_numbers;
|
||||
m_playlist = other->m_playlist;
|
||||
m_pledit_txt = other->m_pledit_txt;
|
||||
|
||||
// TODO: Use default skin for missing information
|
||||
if (!url.isEmpty ()) {
|
||||
m_valid = setSkin (url);
|
||||
} else {
|
||||
m_valid = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Skin::setSkin (const QString& name)
|
||||
|
|
@ -64,11 +75,9 @@ Skin::setSkin (const QString& name)
|
|||
ParsePLEdit() &&
|
||||
BuildNumbers() &&
|
||||
BuildPlaylist () )) {
|
||||
setSkin (defaultSkin);
|
||||
return false;
|
||||
}
|
||||
|
||||
emit skinChanged(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -96,22 +105,6 @@ Skin::getPixmap (const QString& file, const QString &path)
|
|||
const QPixmap
|
||||
Skin::getPixmap (const QString& file)
|
||||
{
|
||||
/* QDir dir;
|
||||
|
||||
dir.setPath (m_path);
|
||||
dir.setFilter (QDir::Files);
|
||||
|
||||
QFileInfoList list = dir.entryInfoList();
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
QFileInfo fileInfo = list.at(i);
|
||||
QString fname = fileInfo.fileName().toLower();
|
||||
if (fname.section(".", 0, 0) == file) {
|
||||
return QPixmap (fileInfo.filePath());
|
||||
}
|
||||
}
|
||||
|
||||
return QPixmap ();
|
||||
*/
|
||||
return getPixmap (file, m_path);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* This file is a part of Promoe, an XMMS2 Client.
|
||||
*
|
||||
* Copyright (C) 2005-2008 XMMS2 Team
|
||||
* Copyright (C) 2005-2010 XMMS2 Team
|
||||
*
|
||||
* 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
|
||||
|
|
@ -34,20 +34,29 @@ class Skin : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static Skin *getInstance (void);
|
||||
Skin (const QString &url);
|
||||
Skin (Skin *other, const QString &url = "");
|
||||
|
||||
const bool isValid () const {return m_valid;}
|
||||
|
||||
bool setSkin (const QString& name);
|
||||
static const QPixmap getPixmap (const QString&, const QString&);
|
||||
|
||||
const QSize getSize (uint item) const { return m_sizes.value (item); };
|
||||
const QSize getSize (uint item) const
|
||||
{ return m_sizes.value (item); }
|
||||
const QPoint getPos (uint item) const
|
||||
{ return m_positions.value (item); };
|
||||
const QIcon getIcon (uint item) const { return m_icons.value(item); };
|
||||
{ return m_positions.value (item); }
|
||||
|
||||
const PixmapMap getNumbers () const
|
||||
{ return m_numbers; }
|
||||
const PixmapMap getSmallNumbers () const
|
||||
{ return m_smallNumbers; }
|
||||
|
||||
const QIcon getIcon (uint item) const
|
||||
{ return m_icons.value(item); }
|
||||
const QPixmapList getBackgrounds (uint item) const
|
||||
{ return m_backgrounds.value(item); };
|
||||
const PixmapMap getNumbers () const { return m_numbers; }
|
||||
const PixmapMap getSmallNumbers () const { return m_smallNumbers; }
|
||||
const PixmapMap getPixmapFont () const { return m_letterMap; }
|
||||
const PixmapMap getPixmapFont () const
|
||||
{ return m_letterMap; }
|
||||
|
||||
const QPixmap getItem (uint part) const { return m_items.value (part); }
|
||||
const QPixmap getPls (uint part) const
|
||||
|
|
@ -56,19 +65,12 @@ class Skin : public QObject
|
|||
const QByteArray getPLeditValue (QByteArray c) const
|
||||
{ return m_pledit_txt.value(c); }
|
||||
|
||||
/* Workaround for programm starup */
|
||||
void emitSkinChanged () { emit skinChanged(this); }
|
||||
|
||||
signals:
|
||||
void skinChanged (Skin *skin);
|
||||
|
||||
private:
|
||||
Skin();
|
||||
static Skin *singleton;
|
||||
|
||||
void setSizes ();
|
||||
void setPositions ();
|
||||
|
||||
bool setSkin (const QString& name);
|
||||
|
||||
const QPixmap getPixmap (const QString& file);
|
||||
bool BuildLetterMap (void);
|
||||
bool BuildButtons (void);
|
||||
|
|
@ -81,6 +83,7 @@ class Skin : public QObject
|
|||
bool ParsePLEdit (void);
|
||||
bool BuildEqualizer (void);
|
||||
|
||||
bool m_valid;
|
||||
QString m_skinname;
|
||||
QString m_path;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* This file is a part of Promoe, an XMMS2 Client.
|
||||
*
|
||||
* Copyright (C) 2005-2008 XMMS2 Team
|
||||
* Copyright (C) 2005-2010 XMMS2 Team
|
||||
*
|
||||
* 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
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "Skin.h"
|
||||
#include "SkinChooser.h"
|
||||
#include "skinmanager.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
|
|
@ -26,8 +27,6 @@
|
|||
|
||||
#include <QtDebug>
|
||||
|
||||
#include "promoe_config.h"
|
||||
|
||||
SkinChooser::SkinChooser (QWidget *parent) : QDialog (parent)
|
||||
{
|
||||
|
||||
|
|
@ -65,19 +64,7 @@ SkinList::SkinList (QWidget *parent) : QListWidget (parent)
|
|||
new SkinChooserItem(icon, skin, path, this);
|
||||
}
|
||||
|
||||
QSettings settings;
|
||||
QStringList searchpath;
|
||||
if (settings.contains ("skin/searchpath") ) {
|
||||
searchpath = settings.value ("skin/searchpath").toStringList ();
|
||||
} else {
|
||||
QString path;
|
||||
path.append (QDir::homePath());
|
||||
path.append ("/.config/xmms2/clients/promoe/skins/");
|
||||
searchpath.append (path);
|
||||
settings.setValue ("skin/searchpath", searchpath);
|
||||
}
|
||||
// This should not be saved in the searchpath config value.
|
||||
searchpath.append (PROMOE_SKINDIR);
|
||||
QStringList searchpath = SkinManager::instance ()->skinPathes ();
|
||||
|
||||
QDir d;
|
||||
d.setFilter (QDir::AllDirs|QDir::NoDotAndDotDot|QDir::Files);
|
||||
|
|
@ -102,13 +89,9 @@ SkinList::SkinList (QWidget *parent) : QListWidget (parent)
|
|||
void
|
||||
SkinList::changeSkin (QListWidgetItem *item)
|
||||
{
|
||||
Skin *skin = Skin::getInstance ();
|
||||
SkinChooserItem *it = dynamic_cast<SkinChooserItem*> (item);
|
||||
|
||||
QSettings settings;
|
||||
|
||||
skin->setSkin (it->getPath ());
|
||||
settings.setValue ("skin/path", it->getPath ());
|
||||
SkinManager::instance ()->loadSkin (it->getPath ());
|
||||
}
|
||||
|
||||
#include "SkinChooser.moc"
|
||||
|
|
|
|||
129
src/skin/skinmanager.cpp
Normal file
129
src/skin/skinmanager.cpp
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
/**
|
||||
* This file is a part of Promoe, an XMMS2 Client.
|
||||
*
|
||||
* Copyright (C) 2005-2010 XMMS2 Team
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "skinmanager.h"
|
||||
#include "Skin.h"
|
||||
|
||||
#include <QSettings>
|
||||
#include <QDebug>
|
||||
#include <QStringList>
|
||||
#include <QDir>
|
||||
|
||||
#include "promoe_config.h"
|
||||
|
||||
static const QString _defaultSkinPath = ":/skins/Almond-blue/";
|
||||
|
||||
static Skin * _defaultSkin = 0;
|
||||
|
||||
SkinManager::SkinManager() : QObject ()
|
||||
{
|
||||
_defaultSkin = new Skin (_defaultSkinPath);
|
||||
|
||||
QSettings settings;
|
||||
const QString skinPath = settings.value("skin/path", _defaultSkinPath)
|
||||
.toString ();
|
||||
m_skin = _defaultSkin;
|
||||
if (skinPath != _defaultSkinPath) {
|
||||
Skin *skin = new Skin (_defaultSkin, skinPath);
|
||||
if (skin->isValid()) {
|
||||
m_skin = skin;
|
||||
} else {
|
||||
qDebug () << "Invalid Skin: " << skinPath;
|
||||
delete skin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SkinManager * SkinManager::instance (void)
|
||||
{
|
||||
static SkinManager *_instance = new SkinManager ();
|
||||
return _instance;
|
||||
}
|
||||
|
||||
Skin * SkinManager::activeSkin (void)
|
||||
{
|
||||
return m_skin;
|
||||
}
|
||||
|
||||
bool SkinManager::loadSkin (QString url)
|
||||
{
|
||||
if (url.isEmpty ()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (url == m_skinPath) {
|
||||
// Already loaded
|
||||
return true;
|
||||
}
|
||||
|
||||
Skin *skin;
|
||||
if (url == _defaultSkinPath) {
|
||||
skin = _defaultSkin;
|
||||
} else {
|
||||
skin = new Skin (_defaultSkin, url);
|
||||
if (!skin->isValid ()) {
|
||||
delete skin;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_skin != _defaultSkin) {
|
||||
delete m_skin;
|
||||
}
|
||||
m_skin = skin;
|
||||
m_skinPath = url;
|
||||
|
||||
QSettings settings;
|
||||
settings.setValue ("skin/path", url);
|
||||
|
||||
emit skinChanged (skin);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkinManager::emitSkinChanged (void)
|
||||
{
|
||||
emit skinChanged (m_skin);
|
||||
}
|
||||
|
||||
QStringList SkinManager::skinPathes () const
|
||||
{
|
||||
QSettings settings;
|
||||
QStringList searchpath;
|
||||
if (settings.contains ("skin/searchpath") ) {
|
||||
searchpath = settings.value ("skin/searchpath").toStringList ();
|
||||
} else {
|
||||
QString path;
|
||||
path.append (QDir::homePath());
|
||||
path.append ("/.config/xmms2/clients/promoe/skins/");
|
||||
searchpath.append (path);
|
||||
settings.setValue ("skin/searchpath", searchpath);
|
||||
}
|
||||
// This should not be saved in the searchpath config value.
|
||||
searchpath.append (PROMOE_SKINDIR);
|
||||
|
||||
return searchpath;
|
||||
}
|
||||
|
||||
void SkinManager::setSkinPathes (QStringList pathes)
|
||||
{
|
||||
QSettings settings;
|
||||
|
||||
pathes.removeAll (PROMOE_SKINDIR);
|
||||
settings.setValue ("skin/searchpath", pathes);
|
||||
}
|
||||
|
||||
#include "skinmanager.moc"
|
||||
50
src/skin/skinmanager.h
Normal file
50
src/skin/skinmanager.h
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* This file is a part of Promoe, an XMMS2 Client.
|
||||
*
|
||||
* Copyright (C) 2005-2010 XMMS2 Team
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __SKINMANAGER_H__
|
||||
#define __SKINMANAGER_H__
|
||||
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
|
||||
class Skin;
|
||||
|
||||
class SkinManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static SkinManager *instance (void);
|
||||
|
||||
Skin *activeSkin (void);
|
||||
bool loadSkin (QString url);
|
||||
|
||||
QStringList skinPathes () const;
|
||||
void setSkinPathes (QStringList pathes);
|
||||
|
||||
// Workaround for process startup
|
||||
void emitSkinChanged ();
|
||||
|
||||
signals:
|
||||
void skinChanged (Skin *skin);
|
||||
|
||||
protected:
|
||||
SkinManager (void);
|
||||
|
||||
Skin *m_skin;
|
||||
QString m_skinPath;
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue