summaryrefslogtreecommitdiffstats
path: root/amarok/src/smartplaylisteditor.h
blob: ca2d4aa42563881fa83d66ac7fe30a11f219ef2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// (c) Pierpaolo Di Panfilo 2004
// (c) Alexandre Pereira de Oliveira 2005
// (c) 2006 Peter C. Ndikuwera <pndiku@gmail.com>
// See COPYING file for licensing information

#ifndef SMARTPLAYLISTEDITOR_H
#define SMARTPLAYLISTEDITOR_H

#include <kdialogbase.h> //baseclass
#include <tqdom.h>
#include <tqhbox.h>       //baseclass
#include <tqptrlist.h>    //definition required
#include <klineedit.h>   //inline function

class KComboBox;
class KIntSpinBox;
class KLineEdit;
class TQCheckBox;
class TQDateEdit;
class TQLabel;
class TQToolButton;
class TQVGroupBox;

class CriteriaEditor;

class SmartPlaylistEditor : public KDialogBase
{
Q_OBJECT
  
    friend class CriteriaEditor;

    public:
        SmartPlaylistEditor( TQString playlist_name, TQWidget *parent, const char *name=0 );
        SmartPlaylistEditor( TQWidget *parent, TQDomElement xml, const char *name=0 );

        TQDomElement result();

        TQString name() const { return m_nameLineEdit->text().replace( "\n", " " ); }

        enum CriteriaType { criteriaAll = 0, criteriaAny = 1 };

    public slots:
        void addCriteriaAny();
        void addCriteriaAny( TQDomElement &xml);
        void removeCriteriaAny( CriteriaEditor *criteria);

        void addCriteriaAll();
        void addCriteriaAll( TQDomElement &xml);
        void removeCriteriaAll( CriteriaEditor *criteria);

    private slots:
        void updateOrderTypes( int index );

    private:
        void init(TQString defaultName);
        void updateMatchWidgets();

        KLineEdit *m_nameLineEdit;

        TQCheckBox *m_matchAnyCheck;
        TQCheckBox *m_matchAllCheck;

        // matching boxes
        TQVGroupBox *m_criteriaAnyGroupBox;
        TQVGroupBox *m_criteriaAllGroupBox;

        //limit widgets
        TQCheckBox *m_limitCheck;
        KIntSpinBox *m_limitSpin;
        //order by widgets
        TQCheckBox *m_orderCheck;
        KComboBox *m_orderCombo;
        KComboBox *m_orderTypeCombo;
        //expand by
        TQCheckBox *m_expandCheck;
        KComboBox *m_expandCombo;

        TQPtrList<CriteriaEditor> m_criteriaEditorAnyList;
        TQPtrList<CriteriaEditor> m_criteriaEditorAllList;
};



class CriteriaEditor : public TQHBox
{
Q_OBJECT
  
    public:
        CriteriaEditor( SmartPlaylistEditor *editor, TQWidget *parent, int criteriaType, TQDomElement criteria = TQDomElement() );
        ~CriteriaEditor();
        TQString getSearchCriteria();
        void setSearchCriteria( const TQString &str );
        TQDomElement getDomSearchCriteria( TQDomDocument &doc );
        void enableRemove( bool );

    private slots:
        void slotRemoveCriteriaAny();
        void slotRemoveCriteriaAll();
        void slotAddCriteriaAny();
        void slotAddCriteriaAll();
        void slotFieldSelected( int );
        void loadEditWidgets();

    private:
        enum ValueType { String, AutoCompletionString, Number, Year, Date, Rating, Length };

        void loadCriteriaList( int valueType, TQString condition = TQString() );
        int getValueType( int fieldIndex );
        inline int indexToRating( int );
        inline int ratingToIndex( int );

        SmartPlaylistEditor *m_playlistEditor;
        int m_currentValueType;
        TQString m_lastCriteria;

        KComboBox *m_fieldCombo;
        KComboBox *m_criteriaCombo;
        TQToolButton *m_addButton;
        TQToolButton *m_removeButton;

        //editing widgets
        TQHBox *m_editBox;
        KLineEdit *m_lineEdit;
        KComboBox *m_comboBox;
        KComboBox *m_comboBox2;
        KIntSpinBox *m_intSpinBox1;
        KIntSpinBox *m_intSpinBox2;
        TQDateEdit *m_dateEdit1;
        TQDateEdit *m_dateEdit2;
        KComboBox *m_dateCombo;
        TQLabel *m_rangeLabel;
	KComboBox *m_lengthCombo;
};

inline int
CriteriaEditor::indexToRating( int index )
{
    if ( index <= 10 && index >= 0 ) return index;
    return -1;
}

inline int
CriteriaEditor::ratingToIndex( int rating )
{
    if ( rating <= 10 && rating >= 0 ) return rating;
    return -1;
}

#endif