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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue