diff --git a/src/application.cpp b/src/application.cpp index 67e2b12..3fb1061 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -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 diff --git a/src/equalizer/equalizerwidget.cpp b/src/equalizer/equalizerwidget.cpp index b545c28..3ec770b 100644 --- a/src/equalizer/equalizerwidget.cpp +++ b/src/equalizer/equalizerwidget.cpp @@ -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 #include @@ -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); diff --git a/src/mainwindow/clutterbar.cpp b/src/mainwindow/clutterbar.cpp index 6c19aaf..8a0bc1e 100644 --- a/src/mainwindow/clutterbar.cpp +++ b/src/mainwindow/clutterbar.cpp @@ -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 #include 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 *))); } diff --git a/src/mainwindow/maindisplay.cpp b/src/mainwindow/maindisplay.cpp index 045b371..f703e57 100644 --- a/src/mainwindow/maindisplay.cpp +++ b/src/mainwindow/maindisplay.cpp @@ -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)); diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index 7ebd900..444ac5b 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -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 #include @@ -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 diff --git a/src/mainwindow/playstatus.cpp b/src/mainwindow/playstatus.cpp index 2347b78..4ddfcc5 100644 --- a/src/mainwindow/playstatus.cpp +++ b/src/mainwindow/playstatus.cpp @@ -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 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); diff --git a/src/mainwindow/posbar.cpp b/src/mainwindow/posbar.cpp index 9196460..01b9103 100644 --- a/src/mainwindow/posbar.cpp +++ b/src/mainwindow/posbar.cpp @@ -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 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); diff --git a/src/mainwindow/shadeddisplay.cpp b/src/mainwindow/shadeddisplay.cpp index c88e0a1..30bbc78 100644 --- a/src/mainwindow/shadeddisplay.cpp +++ b/src/mainwindow/shadeddisplay.cpp @@ -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 (); diff --git a/src/mainwindow/stereomono.cpp b/src/mainwindow/stereomono.cpp index 9753d86..f02c128 100644 --- a/src/mainwindow/stereomono.cpp +++ b/src/mainwindow/stereomono.cpp @@ -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 @@ -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 *))); } diff --git a/src/mainwindow/textscroller.cpp b/src/mainwindow/textscroller.cpp index d136956..0504768 100644 --- a/src/mainwindow/textscroller.cpp +++ b/src/mainwindow/textscroller.cpp @@ -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 #include @@ -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); diff --git a/src/mainwindow/titlebar.cpp b/src/mainwindow/titlebar.cpp index 5b3efd1..e0a422b 100644 --- a/src/mainwindow/titlebar.cpp +++ b/src/mainwindow/titlebar.cpp @@ -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 #include @@ -30,7 +31,7 @@ TitleBar::TitleBar (QWidget *parent, bool shaded) : QWidget (parent) { MainWindow *mw = dynamic_cast(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 *))); } diff --git a/src/playlist/playlistmenu.cpp b/src/playlist/playlistmenu.cpp index d0afced..de60949 100644 --- a/src/playlist/playlistmenu.cpp +++ b/src/playlist/playlistmenu.cpp @@ -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 #include @@ -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 *))); } diff --git a/src/playlist/playlistshade.cpp b/src/playlist/playlistshade.cpp index 30753c6..ca8454f 100644 --- a/src/playlist/playlistshade.cpp +++ b/src/playlist/playlistshade.cpp @@ -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 #include @@ -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()); diff --git a/src/playlist/playlistview.cpp b/src/playlist/playlistview.cpp index 07749be..7d9c12e 100644 --- a/src/playlist/playlistview.cpp +++ b/src/playlist/playlistview.cpp @@ -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 #include @@ -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; diff --git a/src/playlist/playlistwidget.cpp b/src/playlist/playlistwidget.cpp index 1cb206c..823b2ad 100644 --- a/src/playlist/playlistwidget.cpp +++ b/src/playlist/playlistwidget.cpp @@ -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; diff --git a/src/skin/Skin.cpp b/src/skin/Skin.cpp index 7197aeb..4fba0a9 100644 --- a/src/skin/Skin.cpp +++ b/src/skin/Skin.cpp @@ -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 #include -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); } diff --git a/src/skin/Skin.h b/src/skin/Skin.h index 993339d..a62e241 100644 --- a/src/skin/Skin.h +++ b/src/skin/Skin.h @@ -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; diff --git a/src/skin/SkinChooser.cpp b/src/skin/SkinChooser.cpp index 73c7db9..0763160 100644 --- a/src/skin/SkinChooser.cpp +++ b/src/skin/SkinChooser.cpp @@ -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 #include @@ -26,8 +27,6 @@ #include -#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 (item); - QSettings settings; - - skin->setSkin (it->getPath ()); - settings.setValue ("skin/path", it->getPath ()); + SkinManager::instance ()->loadSkin (it->getPath ()); } #include "SkinChooser.moc" diff --git a/src/skin/skinmanager.cpp b/src/skin/skinmanager.cpp new file mode 100644 index 0000000..1e8a0a8 --- /dev/null +++ b/src/skin/skinmanager.cpp @@ -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 +#include +#include +#include + +#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" diff --git a/src/skin/skinmanager.h b/src/skin/skinmanager.h new file mode 100644 index 0000000..a86cdaf --- /dev/null +++ b/src/skin/skinmanager.h @@ -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 +#include + +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