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:
Thomas Frauendorfer 2010-01-29 21:47:12 +01:00
parent 23749446fa
commit ebbcea80b9
20 changed files with 296 additions and 137 deletions

View file

@ -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
@ -20,7 +20,7 @@
#include "mainwindow.h"
#include "equalizerwindow.h"
#include "playlistwindow.h"
#include "Skin.h"
#include "skinmanager.h"
#ifdef HAVE_SERVERBROWSER
#include "Serverbrowser.h"
@ -52,7 +52,7 @@ Application::Application (int &argc, char **argv) : QApplication (argc, argv)
* The windows should fetch their skin information themselfes on startup
* This is a wokaround until all widgets have been fixed
*/
Skin::getInstance()->emitSkinChanged();
SkinManager::instance()->emitSkinChanged();
mw->show ();
// The Playlist- and EqualizerWindow has to become visible after the

View file

@ -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
@ -23,6 +23,8 @@
#include "pixmapbutton.h"
#include "pixmapslider.h"
#include "Skin.h"
#include "skinmanager.h"
#include <QPainter>
#include <QMessageBox>
@ -53,11 +55,11 @@ EqualizerSlider::on_self_slider_moved (int value)
EqualizerWidget::EqualizerWidget (QWidget *parent) : QWidget (parent)
{
Skin *skin = Skin::getInstance ();
Skin *skin = SkinManager::instance ()->activeSkin ();
const XClient *client = App->client ();
m_xconfig = client->xconfig ();
connect (skin, SIGNAL(skinChanged(Skin *)),
connect (SkinManager::instance (), SIGNAL(skinChanged(Skin *)),
this, SLOT(setPixmaps(Skin *)));
m_closebtn = new PixmapButton (this);

View file

@ -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,15 +15,14 @@
#include "clutterbar.h"
#include "Skin.h"
#include "skinmanager.h"
#include <QMouseEvent>
#include <QPainter>
ClutterBar::ClutterBar (QWidget *parent) : QWidget (parent)
{
Skin *skin = Skin::getInstance();
connect (skin, SIGNAL (skinChanged (Skin *)),
connect (SkinManager::instance (), SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps(Skin *)));
}

View file

@ -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
@ -29,6 +29,7 @@
#include "textscroller.h"
#include "timedisplay.h"
#include "Skin.h"
#include "skinmanager.h"
#include "pixmapnumberdisplay.h"
#include "stereomono.h"
#include "posbar.h"
@ -46,9 +47,9 @@ MainDisplay::MainDisplay (MainWindow *parent) : SkinDisplay(parent)
const XClient *client = App->client ();
m_xconfig = client->xconfig ();
m_volumehandler = new VolumeHandler (client);
Skin* skin = Skin::getInstance ();
Skin *skin = SkinManager::instance ()->activeSkin ();
connect (skin, SIGNAL (skinChanged (Skin *)),
connect (SkinManager::instance (), SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps(Skin *)));
m_tbar = new TitleBar(this, false);
@ -258,7 +259,7 @@ void
MainDisplay::SetupToggleButtons (void)
{
QSettings s;
Skin *skin = Skin::getInstance ();
Skin *skin = SkinManager::instance ()->activeSkin ();
m_eq = new PixmapButton (this);
m_eq->setCheckable (true);
@ -299,14 +300,14 @@ MainDisplay::SetupToggleButtons (void)
void
MainDisplay::SetupPushButtons (const XClient* client)
{
Skin *skin = Skin::getInstance ();
Skin *skin = SkinManager::instance ()->activeSkin ();
/* Normal buttons */
m_prev = new PixmapButton (this);
m_prev->resize (skin->getSize (Skin::BUTTON_MW_PREV));
m_prev->move (skin->getPos (Skin::BUTTON_MW_PREV));
connect (m_prev, SIGNAL(clicked()), client->xplayback (), SLOT(prev ()));
m_play = new PixmapButton (this);
m_play->resize (skin->getSize (Skin::BUTTON_MW_PLAY));
m_play->move (skin->getPos (Skin::BUTTON_MW_PLAY));

View file

@ -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
@ -28,6 +28,7 @@
#include "shadeddisplay.h"
#include "equalizerwindow.h"
#include "Skin.h"
#include "skinmanager.h"
#include <QSettings>
#include <QIcon>
@ -102,7 +103,8 @@ MainWindow::MainWindow (QWidget *parent) : BaseWindow (parent)
MainWindow::~MainWindow ()
{
delete Skin::getInstance ();
//FIXME: This should perhaps go somewhere else
delete SkinManager::instance ();
}
void

View file

@ -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,13 +15,13 @@
#include "playstatus.h"
#include "Skin.h"
#include "skinmanager.h"
#include <QPainter>
PlayStatus::PlayStatus (QWidget *parent) : QWidget (parent)
{
Skin* skin = Skin::getInstance ();
connect (skin, SIGNAL (skinChanged (Skin *)),
connect (SkinManager::instance (), SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps (Skin *)));
setFixedSize(11, 9);

View file

@ -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,18 +15,18 @@
#include "posbar.h"
#include "Skin.h"
#include "skinmanager.h"
#include <QWidget>
PosBar::PosBar (QWidget *parent, uint bg, uint bnormal, uint bpressed)
: PixmapSlider (parent)
{
Skin *skin = Skin::getInstance ();
m_slider_normal = bnormal;
m_slider_pressed = bpressed;
m_bg = bg;
connect (skin, SIGNAL (skinChanged (Skin *)),
connect (SkinManager::instance (), SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps (Skin *)));
setFixedSize (248, 10);

View file

@ -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,6 +19,7 @@
#include "application.h"
#include "shadeddisplay.h"
#include "skinmanager.h"
#include "titlebar.h"
#include "pixmapbutton.h"
@ -29,9 +30,7 @@
ShadedDisplay::ShadedDisplay (QWidget *parent) : SkinDisplay (parent)
{
Skin *skin = Skin::getInstance ();
connect (skin, SIGNAL (skinChanged (Skin *)),
connect (SkinManager::instance (), SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps(Skin *)));
const XClient *client = App->client ();

View file

@ -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 "stereomono.h"
#include "Skin.h"
#include "skinmanager.h"
#include <QPainter>
@ -23,8 +24,7 @@ StereoMono::StereoMono (QWidget *parent)
{
setFixedSize (56, 12);
Skin *skin = Skin::getInstance();
connect (skin, SIGNAL (skinChanged (Skin *)),
connect (SkinManager::instance (), SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps (Skin *)));
}

View file

@ -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
@ -16,6 +16,7 @@
#include "skindisplay.h"
#include "textscroller.h"
#include "Skin.h"
#include "skinmanager.h"
#include <QBrush>
#include <QFont>
@ -33,9 +34,7 @@
TextScroller::TextScroller (QWidget *parent, uint w,
uint h, const QString &name) : QWidget (parent)
{
Skin *skin = Skin::getInstance ();
connect (skin, SIGNAL (skinChanged (Skin *)),
connect (SkinManager::instance (), SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps(Skin *)));
QSettings s;
@ -147,7 +146,7 @@ TextScroller::drawText ()
void
TextScroller::drawBitmapFont (QString text)
{
Skin *skin = Skin::getInstance ();
Skin *skin = SkinManager::instance ()->activeSkin ();
int w = text.length() * 5;
QString temp = text.toLower ();
@ -182,7 +181,7 @@ TextScroller::drawBitmapFont (QString text)
void
TextScroller::drawQtFont (QString text)
{
Skin *skin = Skin::getInstance ();
Skin *skin = SkinManager::instance ()->activeSkin ();
QFont font(skin->getPLeditValue ("font"));
font.setPixelSize (m_fontsize);

View file

@ -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
@ -22,6 +22,7 @@
#include "pixmapbutton.h"
#include "BrowseDialog.h"
#include "Skin.h"
#include "skinmanager.h"
#include <QMenu>
#include <QPainter>
@ -30,7 +31,7 @@ TitleBar::TitleBar (QWidget *parent, bool shaded) : QWidget (parent)
{
MainWindow *mw = dynamic_cast<MainWindow*>(window ());
m_shaded = shaded;
Skin *skin = Skin::getInstance ();
Skin *skin = SkinManager::instance ()->activeSkin ();
setFixedSize (275, 14);
@ -61,7 +62,7 @@ TitleBar::TitleBar (QWidget *parent, bool shaded) : QWidget (parent)
connect (m_closebtn, SIGNAL (clicked()), qApp, SLOT (quit ()));
m_pixmap = QPixmap(0,0);
connect (skin, SIGNAL (skinChanged (Skin *)),
connect (SkinManager::instance (), SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps(Skin *)));
}

View file

@ -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 "playlistmenu.h"
#include "Skin.h"
#include "skinmanager.h"
#include <QMouseEvent>
#include <QWidget>
@ -25,11 +26,9 @@
PlaylistMenuBar::PlaylistMenuBar (QWidget *parent, uint id) : QWidget (parent)
{
m_id = id;
Skin *skin = Skin::getInstance ();
m_pixmap = QPixmap (0,0);
connect (skin, SIGNAL (skinChanged (Skin *)),
connect (SkinManager::instance (), SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps (Skin *)));
}
@ -92,11 +91,9 @@ PlaylistMenu::PlaylistMenu (QWidget *parent, uint pix,
m_decbar->move (0, 0);
m_pixid = pix;
Skin *skin = Skin::getInstance ();
m_pixmap = QPixmap (0,0);
connect (skin, SIGNAL (skinChanged (Skin *)),
connect (SkinManager::instance (), SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps (Skin *)));
}

View file

@ -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
@ -21,6 +21,7 @@
#include "playlistwindow.h"
#include "pixmapbutton.h"
#include "Skin.h"
#include "skinmanager.h"
#include <QSettings>
#include <QPainter>
@ -36,8 +37,8 @@ PlaylistShade::PlaylistShade (PlaylistWindow *parent) : QWidget (parent)
if (!s.contains ("playlist/shadedsize"))
s.setValue ("playlist/shadedsize", 8);
Skin *skin = Skin::getInstance ();
connect (skin, SIGNAL (skinChanged (Skin *)),
Skin *skin = SkinManager::instance ()->activeSkin ();
connect (SkinManager::instance (), SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps(Skin *)));
m_closebtn = new PixmapButton (this);
@ -88,7 +89,7 @@ PlaylistShade::setMediainfo (QVariantHash info)
void
PlaylistShade::resizeEvent (QResizeEvent *event)
{
Skin *skin = Skin::getInstance ();
Skin *skin = SkinManager::instance ()->activeSkin ();
QPoint p = skin->getPos (Skin::BUTTON_PLS_CLOSE);
m_closebtn->move (p.x () + width (), p.y());

View file

@ -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
@ -22,6 +22,7 @@
#include "playlistwidget.h"
#include "Skin.h"
#include "entryinfo.h"
#include "skinmanager.h"
#include <QColor>
#include <QMenu>
@ -108,7 +109,7 @@ PlaylistDelegate::sizeHint ( const QStyleOptionViewItem &option,
PlaylistView::PlaylistView (QWidget *parent) : QListView (parent)
{
QSettings s;
Skin *skin = Skin::getInstance ();
Skin *skin = SkinManager::instance ()->activeSkin ();
if (!s.contains ("playlist/fontsize"))
s.setValue ("playlist/fontsize", 10);
@ -128,7 +129,7 @@ PlaylistView::PlaylistView (QWidget *parent) : QListView (parent)
// TODO make sure delegate gets deleted
setItemDelegate (new PlaylistDelegate (this));
connect (skin, SIGNAL (skinChanged (Skin *)),
connect (SkinManager::instance (), SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps(Skin *)));
m_font = NULL;

View file

@ -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
@ -25,6 +25,7 @@
#include "playlistwidget.h"
#include "playlistview.h"
#include "playlistcontrols.h"
#include "skinmanager.h"
#include "pixmapbutton.h"
#include "playlistshade.h"
@ -51,15 +52,13 @@
PlaylistScrollBar::PlaylistScrollBar (QWidget *parent) :
QScrollBar (Qt::Vertical, parent)
{
Skin *skin = Skin::getInstance ();
setContextMenuPolicy(Qt::NoContextMenu);
m_pixmap = QPixmap (0, 0);
m_slider = QPixmap (0, 0);
m_slider_down = QPixmap (0, 0);
connect (skin, SIGNAL (skinChanged (Skin *)),
connect (SkinManager::instance (), SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps(Skin *)));
}
@ -176,9 +175,9 @@ PlaylistScrollBar::sliderValueFromPosition (int position)
*/
PlaylistWidget::PlaylistWidget (PlaylistWindow *parent) : QWidget (parent)
{
Skin *skin = Skin::getInstance ();
Skin *skin = SkinManager::instance ()->activeSkin ();
connect (skin, SIGNAL (skinChanged (Skin *)),
connect (SkinManager::instance (), SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps(Skin *)));
setActive (underMouse ());
@ -413,7 +412,7 @@ PlaylistWidget::menuAddPls ()
void
PlaylistWidget::resizeEvent (QResizeEvent *event)
{
Skin *skin = Skin::getInstance ();
Skin *skin = SkinManager::instance ()->activeSkin ();
QPoint p = skin->getPos (Skin::BUTTON_PLS_CLOSE);
m_closebtn->move (p.x () + width (), p.y());
@ -466,7 +465,7 @@ PlaylistWidget::setPixmaps (Skin *skin)
void
PlaylistWidget::setActive (bool active)
{
Skin *skin = Skin::getInstance ();
Skin *skin = SkinManager::instance ()->activeSkin ();
m_active = active;

View file

@ -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);
}

View file

@ -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;

View file

@ -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
View 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
View 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