playlistsearch.h 3.45 KB
Newer Older
1
/***************************************************************************
2
                          playlistsearch.h
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
                             -------------------
    begin                : Sun Mar 6 2003
    copyright            : (C) 2003 by Scott Wheeler
    email                : wheeler@kde.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef PLAYLISTSEARCH_H
#define PLAYLISTSEARCH_H

#include <qvaluelist.h>
22
#include <qregexp.h>
23

Scott Wheeler's avatar
Scott Wheeler committed
24 25 26 27
class Playlist;
typedef QValueList<Playlist *> PlaylistList;
class PlaylistItem;
typedef QValueList<PlaylistItem *> PlaylistItemList;
28
typedef QValueList<int> ColumnList;
29 30 31 32 33

class PlaylistSearch
{
public:
    class Component;
Scott Wheeler's avatar
Scott Wheeler committed
34
    typedef QValueList<Component> ComponentList;
35 36 37

    enum SearchMode { MatchAny = 0, MatchAll = 1 };

Scott Wheeler's avatar
Scott Wheeler committed
38
    PlaylistSearch();
Scott Wheeler's avatar
Scott Wheeler committed
39
    PlaylistSearch(const PlaylistSearch &search);
40 41 42 43 44 45 46 47
    PlaylistSearch(const PlaylistList &playlists,
		   const ComponentList &components,
		   SearchMode mode = MatchAny);


    PlaylistItemList searchedItems() const { return m_items; }
    PlaylistItemList matchedItems() const { return m_matchedItems; }
    PlaylistItemList unmatchedItems() const { return m_unmatchedItems; }
48 49 50

    PlaylistList playlists() const { return m_playlists; }

Scott Wheeler's avatar
Scott Wheeler committed
51 52 53
    ComponentList components() const { return m_components; }

    bool isNull() const { return m_components.isEmpty(); }
54
    bool isEmpty() const;
Scott Wheeler's avatar
Scott Wheeler committed
55

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
private:
    void search();

    PlaylistList m_playlists;
    ComponentList m_components;
    SearchMode m_mode;

    PlaylistItemList m_items;
    PlaylistItemList m_matchedItems;
    PlaylistItemList m_unmatchedItems;
};

/**
 * A search is built from several search components.  These corespond to to lines
 * in the search bar.
 */

class PlaylistSearch::Component
{
public:
Scott Wheeler's avatar
Scott Wheeler committed
76 77 78 79 80 81 82 83 84 85 86 87

    /**
     * Create an empty search component.  This is only provided for use by 
     * QValueList and should not be used in any other context.
     */
    Component();

    /**
     * Copy constructor.
     */
    Component(const Component &component);

88 89 90
    /**
     * Create a query component.  This defaults to searching all visible coulumns.
     */
91
    Component(const QString &query, bool caseSensitive = false, const ColumnList &columns = ColumnList());
92

93 94 95 96 97
    /**
     * Create a query component.  This defaults to searching all visible coulumns.
     */
    Component(const QRegExp &query, const ColumnList &columns = ColumnList());

98
    QString query() const { return m_query; }
Scott Wheeler's avatar
Scott Wheeler committed
99
    QRegExp pattern() const { return m_queryRe; }
100 101 102
    ColumnList columns() const { return m_columns; }

    bool matches(PlaylistItem *item);
Scott Wheeler's avatar
Scott Wheeler committed
103 104
    bool isPatternSearch() const { return m_re; }
    bool isCaseSensitive() const { return m_caseSensitive; }
105 106 107
    
private:
    QString m_query;
108
    QRegExp m_queryRe;
109 110 111
    ColumnList m_columns;
    bool m_searchAllVisible;
    bool m_caseSensitive;
112
    bool m_re;
113 114 115 116
};


#endif