Revert previous commit, was incorrect
[amarok.git] / src / SmartPlaylistEditor.h
blobe54d8f082b8fc26ffcc674b844148509b95803f3
1 // (c) Pierpaolo Di Panfilo 2004
2 // (c) Alexandre Pereira de Oliveira 2005
3 // (c) 2006 Peter C. Ndikuwera <pndiku@gmail.com>
4 // (c) 2007 Seb Ruiz <ruiz@kde.org>
5 // See COPYING file for licensing information
7 #ifndef SMARTPLAYLISTEDITOR_H
8 #define SMARTPLAYLISTEDITOR_H
10 #include <KDialog> //baseclass
11 #include <klineedit.h> //inline function
12 #include <KHBox> //baseclass
14 #include <QDateEdit>
15 #include <QDomDocument>
16 #include <QDomElement>
18 class CriteriaEditor;
20 class KComboBox;
21 class KLineEdit;
23 class QGroupBox;
24 class QCheckBox;
25 class QLabel;
26 class QSpinBox;
27 class QToolButton;
29 class SmartPlaylistEditor : public KDialog
31 Q_OBJECT
32 friend class CriteriaEditor;
34 public:
35 SmartPlaylistEditor( QString defaultName, QWidget *parent, const char *name=0 );
36 SmartPlaylistEditor( QWidget *parent, QDomElement xml, const char *name=0 );
38 QDomElement result();
40 QString name() const { return m_nameLineEdit->text().replace( "\n", " " ); }
42 enum CriteriaType { criteriaAll = 0, criteriaAny = 1 };
44 public slots:
45 void addCriteriaAny();
46 void addCriteriaAny( QDomElement &xml);
47 void removeCriteriaAny( CriteriaEditor *criteria);
49 void addCriteriaAll();
50 void addCriteriaAll( QDomElement &xml);
51 void removeCriteriaAll( CriteriaEditor *criteria);
53 private slots:
54 void updateOrderTypes( int index );
56 private:
57 void init(QString defaultName);
58 void updateMatchWidgets();
60 KLineEdit *m_nameLineEdit;
62 QCheckBox *m_matchAnyCheck;
63 QCheckBox *m_matchAllCheck;
65 // matching boxes
66 QGroupBox *m_criteriaAnyGroupBox;
67 QGroupBox *m_criteriaAllGroupBox;
69 //limit widgets
70 QCheckBox *m_limitCheck;
71 QSpinBox *m_limitSpin;
72 //order by widgets
73 QCheckBox *m_orderCheck;
74 KComboBox *m_orderCombo;
75 KComboBox *m_orderTypeCombo;
76 //expand by
77 QCheckBox *m_expandCheck;
78 KComboBox *m_expandCombo;
80 QList<CriteriaEditor*> m_criteriaEditorAnyList;
81 QList<CriteriaEditor*> m_criteriaEditorAllList;
86 class CriteriaEditor : public KHBox
88 Q_OBJECT
89 public:
90 CriteriaEditor( SmartPlaylistEditor *editor, QWidget *parent, int criteriaType, QDomElement criteria = QDomElement() );
91 ~CriteriaEditor();
92 QString getSearchCriteria();
93 void setSearchCriteria( const QString &str );
94 QDomElement getDomSearchCriteria( QDomDocument &doc );
95 void enableRemove( bool );
97 private slots:
98 void slotRemoveCriteriaAny();
99 void slotRemoveCriteriaAll();
100 void slotAddCriteriaAny();
101 void slotAddCriteriaAll();
102 void slotFieldSelected( int );
103 void loadEditWidgets();
105 private:
106 enum ValueType { String, AutoCompletionString, Number, Year, Date, Rating, Length };
108 void loadCriteriaList( int valueType, QString condition = QString() );
109 int getValueType( int fieldIndex );
110 inline int indexToRating( int );
111 inline int ratingToIndex( int );
113 SmartPlaylistEditor *m_playlistEditor;
114 int m_currentValueType;
115 QString m_lastCriteria;
117 KComboBox *m_fieldCombo;
118 KComboBox *m_criteriaCombo;
119 QToolButton *m_addButton;
120 QToolButton *m_removeButton;
122 //editing widgets
123 KHBox *m_editBox;
124 KLineEdit *m_lineEdit;
125 KComboBox *m_comboBox;
126 KComboBox *m_comboBox2;
127 QSpinBox *m_intSpinBox1;
128 QSpinBox *m_intSpinBox2;
129 QDateEdit *m_dateEdit1;
130 QDateEdit *m_dateEdit2;
131 KComboBox *m_dateCombo;
132 QLabel *m_rangeLabel;
133 KComboBox *m_lengthCombo;
136 inline int
137 CriteriaEditor::indexToRating( int index )
139 if ( index <= 10 && index >= 0 ) return index;
140 return -1;
143 inline int
144 CriteriaEditor::ratingToIndex( int rating )
146 if ( rating <= 10 && rating >= 0 ) return rating;
147 return -1;
150 #endif