OTHER: Use a iterator class for loading skins
This commit is contained in:
parent
2e02c96263
commit
389b847426
8 changed files with 333 additions and 32 deletions
109
dir_iterator/diriterator.cpp
Normal file
109
dir_iterator/diriterator.cpp
Normal file
|
@ -0,0 +1,109 @@
|
|||
/**
|
||||
* This file is a part of Promoe, an XMMS2 Client.
|
||||
*
|
||||
* Copyright (C) 2010 XMMS2 Team
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "diriterator.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
DirIterator::DirIterator (const QDir & dir)
|
||||
{
|
||||
m_dir = dir;
|
||||
finish_init ();
|
||||
}
|
||||
|
||||
DirIterator::DirIterator (const QString & path)
|
||||
{
|
||||
m_dir = QDir (path);
|
||||
}
|
||||
|
||||
DirIterator::~DirIterator ()
|
||||
{
|
||||
if (m_device != 0)
|
||||
delete m_device;
|
||||
}
|
||||
|
||||
void
|
||||
DirIterator::finish_init ()
|
||||
{
|
||||
if (!m_dir.exists ()) {
|
||||
m_exists = false;
|
||||
return;
|
||||
}
|
||||
|
||||
m_exists = true;
|
||||
m_current = -1;
|
||||
entryList = m_dir.entryList ();
|
||||
m_device = 0;
|
||||
}
|
||||
|
||||
QString
|
||||
DirIterator::next ()
|
||||
{
|
||||
if (!m_exists || (m_current +1) >= entryList.size ())
|
||||
return QString();
|
||||
|
||||
m_current++;
|
||||
|
||||
if (m_device != 0) {
|
||||
m_device->close ();
|
||||
delete m_device;
|
||||
m_device = 0;
|
||||
}
|
||||
|
||||
return entryList.at (m_current);
|
||||
}
|
||||
|
||||
bool
|
||||
DirIterator::hasNext ()
|
||||
{
|
||||
return (m_exists && ((m_current +1) < entryList.size ()));
|
||||
}
|
||||
|
||||
QString
|
||||
DirIterator::pathName ()
|
||||
{
|
||||
if (!m_exists || m_current >= entryList.size ())
|
||||
return QString ();
|
||||
|
||||
return entryList.at (m_current);
|
||||
}
|
||||
|
||||
QPointer<QIODevice>
|
||||
DirIterator::entry ()
|
||||
{
|
||||
if (!m_exists || m_current >= entryList.size ())
|
||||
return 0;
|
||||
|
||||
if (m_device != 0) {
|
||||
if (m_device->isOpen ()) {
|
||||
return m_device;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
m_device = new QFile (m_dir.absoluteFilePath (entryList.at (m_current)));
|
||||
if (!m_device->open (QIODevice::ReadOnly)) {
|
||||
qDebug() << entryList.at (m_current);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_device;
|
||||
}
|
||||
|
||||
#include "diriterator.moc"
|
53
dir_iterator/diriterator.h
Normal file
53
dir_iterator/diriterator.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* This file is a part of Promoe, an XMMS2 Client.
|
||||
*
|
||||
* Copyright (C) 2010 XMMS2 Team
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef __DIRITERATOR_H__
|
||||
#define __DIRITERATOR_H__
|
||||
|
||||
#include "diriteratorbase.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QDir>
|
||||
#include <QStringList>
|
||||
|
||||
|
||||
class DirIterator : public QObject, public virtual DirIteratorBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DirIterator (const QDir & dir);
|
||||
DirIterator (const QString & path);
|
||||
virtual ~DirIterator ();
|
||||
|
||||
virtual QString next ();
|
||||
virtual QString pathName ();
|
||||
virtual bool hasNext ();
|
||||
|
||||
virtual QPointer<QIODevice> entry ();
|
||||
|
||||
private:
|
||||
void finish_init ();
|
||||
|
||||
bool m_exists;
|
||||
int m_current;
|
||||
QDir m_dir;
|
||||
QStringList entryList;
|
||||
QIODevice * m_device;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
37
dir_iterator/diriteratorbase.cpp
Normal file
37
dir_iterator/diriteratorbase.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* This file is a part of Promoe, an XMMS2 Client.
|
||||
*
|
||||
* Copyright (C) 2010 XMMS2 Team
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "diriteratorbase.h"
|
||||
#include <QDataStream>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
QPixmap
|
||||
DirIteratorBase::pixmapEntry ()
|
||||
{
|
||||
QPointer<QIODevice> d = entry ();
|
||||
if (d == 0) {
|
||||
return QPixmap ();
|
||||
}
|
||||
|
||||
QByteArray a = d->readAll ();
|
||||
|
||||
QPixmap p;
|
||||
p.loadFromData(a);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
43
dir_iterator/diriteratorbase.h
Normal file
43
dir_iterator/diriteratorbase.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* This file is a part of Promoe, an XMMS2 Client.
|
||||
*
|
||||
* Copyright (C) 2010 XMMS2 Team
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef __DIRITERATORBASE_H__
|
||||
#define __DIRITERATIRBASE_H__
|
||||
|
||||
#include <QString>
|
||||
#include <QPointer>
|
||||
#include <QIODevice>
|
||||
#include <QPixmap>
|
||||
|
||||
class DirIteratorBase
|
||||
{
|
||||
public:
|
||||
virtual ~DirIteratorBase () {}
|
||||
|
||||
virtual QString next () = 0;
|
||||
virtual QString pathName () = 0;
|
||||
virtual bool hasNext () = 0;
|
||||
|
||||
virtual QPointer<QIODevice> entry () = 0;
|
||||
|
||||
// Included because I'm lazy, returns a QPixmap for the current entry.
|
||||
// If no pixmap can be createt for the current entry, an empty pixmap is
|
||||
// returned
|
||||
QPixmap pixmapEntry ();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
55
dir_iterator/wscript
Normal file
55
dir_iterator/wscript
Normal file
|
@ -0,0 +1,55 @@
|
|||
# encoding: utf-8
|
||||
# vim:set syntax=python expandtab :
|
||||
|
||||
"""
|
||||
This file is a part of Promoe, an XMMS2 Client
|
||||
|
||||
Copyright (C) 2009-2010 XMMS2 Team
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. The name of the author may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
"""
|
||||
|
||||
lib_source = """
|
||||
diriteratorbase.cpp
|
||||
diriterator.cpp
|
||||
"""
|
||||
|
||||
|
||||
def set_options(opt):
|
||||
pass
|
||||
def configure(conf):
|
||||
pass
|
||||
def build(bld):
|
||||
obj = bld.new_task_gen(features='qt4 cstaticlib cxx')
|
||||
obj.target = 'dir_iterator'
|
||||
obj.install_path = 0 # Don't install
|
||||
obj.includes = '.'
|
||||
obj.source = lib_source
|
||||
obj.uselib = 'QTCORE QTGUI'
|
||||
obj.export_incdirs = '.'
|
||||
pass
|
||||
|
|
@ -15,10 +15,14 @@
|
|||
|
||||
#include "skin.h"
|
||||
|
||||
#include "diriterator.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QPainter>
|
||||
#include <QSettings>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
Skin::Skin (const QString &url)
|
||||
{
|
||||
setSizes ();
|
||||
|
@ -657,65 +661,62 @@ Skin::setSkin (const QString& path)
|
|||
QPixmap p_numbers;
|
||||
QPixmap p_volume;
|
||||
|
||||
dir.setFilter (QDir::Files|QDir::NoDotAndDotDot);
|
||||
QStringList entries = dir.entryList ();
|
||||
for (int i = 0; i < entries.size (); i++) {
|
||||
QString filename = entries.at (i);
|
||||
QString entry = filename.toLower ();
|
||||
DirIterator *iter = new DirIterator(dir);
|
||||
|
||||
while (iter->hasNext ()) {
|
||||
QString entry = iter->next ().toLower ();
|
||||
if (entry.endsWith (".txt")) {
|
||||
QFile f (dir.absoluteFilePath (filename));
|
||||
if (!f.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
QPointer<QIODevice> d = iter->entry ();
|
||||
if (d == 0)
|
||||
continue;
|
||||
d->setTextModeEnabled (true);
|
||||
if ( entry == "pledit.txt") {
|
||||
b_pledit_txt = handle_pledit_txt (&f);
|
||||
b_pledit_txt = handle_pledit_txt (d);
|
||||
}
|
||||
continue;
|
||||
} else if (entry.endsWith (".cur")) {
|
||||
// Cursor files are not supported yet
|
||||
continue;
|
||||
} else {
|
||||
QPixmap img = QPixmap (dir.absoluteFilePath (filename));
|
||||
if (img.isNull ()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
entry = entry.section(".", 0, 0);
|
||||
if (entry == "main") {
|
||||
b_main = handle_main (img);
|
||||
b_main = handle_main (iter->pixmapEntry ());
|
||||
} else if (entry == "titlebar") {
|
||||
b_titlebar = handle_titlebar (img);
|
||||
b_titlebar = handle_titlebar (iter->pixmapEntry ());
|
||||
} else if (entry == "posbar" ) {
|
||||
b_posbar = handle_posbar (img);
|
||||
b_posbar = handle_posbar (iter->pixmapEntry ());
|
||||
} else if (entry == "volume") {
|
||||
p_volume = img;
|
||||
b_volume = handle_volume (img);
|
||||
p_volume = iter->pixmapEntry ();
|
||||
b_volume = handle_volume (p_volume);
|
||||
} else if (entry == "balance") {
|
||||
b_balance = handle_balance (img);
|
||||
b_balance = handle_balance (iter->pixmapEntry ());
|
||||
} else if (entry == "cbuttons") {
|
||||
b_cbuttons = handle_cbuttons (img);
|
||||
b_cbuttons = handle_cbuttons (iter->pixmapEntry ());
|
||||
} else if (entry == "monoster") {
|
||||
b_monoster = handle_monoster (img);
|
||||
b_monoster = handle_monoster (iter->pixmapEntry ());
|
||||
} else if (entry == "playpaus") {
|
||||
b_playpaus = handle_playpaus (img);
|
||||
b_playpaus = handle_playpaus (iter->pixmapEntry ());
|
||||
} else if (entry == "shufrep") {
|
||||
b_shufrep = handle_shufrep (img);
|
||||
b_shufrep = handle_shufrep (iter->pixmapEntry ());
|
||||
} else if (entry == "text") {
|
||||
b_text = handle_text (img);
|
||||
b_text = handle_text (iter->pixmapEntry ());
|
||||
} else if (entry == "nums_ex") {
|
||||
b_numbers = handle_numbers (img);
|
||||
b_numbers = handle_numbers (iter->pixmapEntry ());
|
||||
} else if (entry == "numbers") {
|
||||
p_numbers = img;
|
||||
p_numbers = iter->pixmapEntry ();
|
||||
} else if (entry == "eqmain") {
|
||||
b_eqmain = handle_eqmain (img);
|
||||
b_eqmain = handle_eqmain (iter->pixmapEntry ());
|
||||
} else if (entry == "eq_ex") {
|
||||
p_eq_ex = img;
|
||||
p_eq_ex = iter->pixmapEntry ();
|
||||
} else if (entry == "pledit") {
|
||||
b_pledit = handle_pledit (img);
|
||||
b_pledit = handle_pledit (iter->pixmapEntry ());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
delete iter;
|
||||
|
||||
if (!b_balance) {
|
||||
// Fallback, use volume image if skin has no balance image
|
||||
handle_balance (p_volume);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"""
|
||||
This file is a part of Promoe, an XMMS2 Client
|
||||
|
||||
Copyright (C) 2009 XMMS2 Team
|
||||
Copyright (C) 2009-2010 XMMS2 Team
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
@ -97,7 +97,7 @@ def build(bld):
|
|||
obj.target = 'promoe'
|
||||
obj.includes = incdirs
|
||||
obj.source = sources
|
||||
obj.uselib_local = 'backend_lib'
|
||||
obj.uselib_local = 'backend_lib dir_iterator'
|
||||
obj.add_objects = 'promoe_data'
|
||||
obj.uselib = 'QTCORE QTGUI AVAHI-CLIENT AVAHI-QT4'
|
||||
pass
|
||||
|
|
5
wscript
5
wscript
|
@ -4,7 +4,7 @@
|
|||
"""
|
||||
This file is a part of Promoe, an XMMS2 Client
|
||||
|
||||
Copyright (C) 2009 XMMS2 Team
|
||||
Copyright (C) 2009-2010 XMMS2 Team
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
@ -46,6 +46,7 @@ def set_options(opt):
|
|||
opt.tool_options('qt4')
|
||||
|
||||
opt.sub_options('backend_xmmsclient++')
|
||||
opt.sub_options('dir_iterator')
|
||||
opt.sub_options('data')
|
||||
opt.sub_options('src')
|
||||
|
||||
|
@ -67,6 +68,7 @@ def configure(conf):
|
|||
|
||||
|
||||
conf.sub_config('backend_xmmsclient++')
|
||||
conf.sub_config('dir_iterator')
|
||||
conf.sub_config('data')
|
||||
conf.sub_config('src')
|
||||
|
||||
|
@ -77,6 +79,7 @@ def configure(conf):
|
|||
|
||||
def build(bld):
|
||||
bld.add_subdirs('backend_xmmsclient++')
|
||||
bld.add_subdirs('dir_iterator')
|
||||
bld.add_subdirs('data')
|
||||
bld.add_subdirs('src')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue