Not crap after all...
[amarok.git] / src / smartplaylisteditor.h
blobd4c2ed054979423a7ce13f1b025923972bd8f73e
1 // (c) Pierpaolo Di Panfilo 2004
2 // (c) Alexandre Pereira de Oliveira 2005
3 // (c) 2006 Peter C. Ndikuwera <pndiku@gmail.com>
4 // See COPYING file for licensing information
6 #ifndef SMARTPLAYLISTEDITOR_H
7 #define SMARTPLAYLISTEDITOR_H
9 #include <kdialog.h> //baseclass
10 #include <qdom.h>
11 #include <khbox.h> //baseclass
12 #include <q3ptrlist.h> //definition required
13 //Added by qt3to4:
14 #include <QLabel>
15 #include <klineedit.h> //inline function
17 class KComboBox;
18 class QSpinBox;
19 class KLineEdit;
20 class QCheckBox;
21 class Q3DateEdit;
22 class QLabel;
23 class QToolButton;
24 class Q3VGroupBox;
26 class CriteriaEditor;
28 class SmartPlaylistEditor : public KDialog
30 Q_OBJECT
31 friend class CriteriaEditor;
33 public:
34 SmartPlaylistEditor( QString defaultName, QWidget *parent, const char *name=0 );
35 SmartPlaylistEditor( QWidget *parent, QDomElement xml, const char *name=0 );
37 QDomElement result();
39 QString name() const { return m_nameLineEdit->text().replace( "\n", " " ); }
41 enum CriteriaType { criteriaAll = 0, criteriaAny = 1 };
43 public slots:
44 void addCriteriaAny();
45 void addCriteriaAny( QDomElement &xml);
46 void removeCriteriaAny( CriteriaEditor *criteria);
48 void addCriteriaAll();
49 void addCriteriaAll( QDomElement &xml);
50 void removeCriteriaAll( CriteriaEditor *criteria);
52 private slots:
53 void updateOrderTypes( int index );
55 private:
56 void init(QString defaultName);
57 void updateMatchWidgets();
59 KLineEdit *m_nameLineEdit;
61 QCheckBox *m_matchAnyCheck;
62 QCheckBox *m_matchAllCheck;
64 // matching boxes
65 Q3VGroupBox *m_criteriaAnyGroupBox;
66 Q3VGroupBox *m_criteriaAllGroupBox;
68 //limit widgets
69 QCheckBox *m_limitCheck;
70 QSpinBox *m_limitSpin;
71 //order by widgets
72 QCheckBox *m_orderCheck;
73 KComboBox *m_orderCombo;
74 KComboBox *m_orderTypeCombo;
75 //expand by
76 QCheckBox *m_expandCheck;
77 KComboBox *m_expandCombo;
79 Q3PtrList<CriteriaEditor> m_criteriaEditorAnyList;
80 Q3PtrList<CriteriaEditor> m_criteriaEditorAllList;
85 class CriteriaEditor : public KHBox
87 Q_OBJECT
88 public:
89 CriteriaEditor( SmartPlaylistEditor *editor, QWidget *parent, int criteriaType, QDomElement criteria = QDomElement() );
90 ~CriteriaEditor();
91 QString getSearchCriteria();
92 void setSearchCriteria( const QString &str );
93 QDomElement getDomSearchCriteria( QDomDocument &doc );
94 void enableRemove( bool );
96 private slots:
97 void slotRemoveCriteriaAny();
98 void slotRemoveCriteriaAll();
99 void slotAddCriteriaAny();
100 void slotAddCriteriaAll();
101 void slotFieldSelected( int );
102 void loadEditWidgets();
104 private:
105 enum ValueType { String, AutoCompletionString, Number, Year, Date, Rating, Length };
107 void loadCriteriaList( int valueType, QString condition = QString() );
108 int getValueType( int fieldIndex );
109 inline int indexToRating( int );
110 inline int ratingToIndex( int );
112 SmartPlaylistEditor *m_playlistEditor;
113 int m_currentValueType;
114 QString m_lastCriteria;
116 KComboBox *m_fieldCombo;
117 KComboBox *m_criteriaCombo;
118 QToolButton *m_addButton;
119 QToolButton *m_removeButton;
121 //editing widgets
122 KHBox *m_editBox;
123 KLineEdit *m_lineEdit;
124 KComboBox *m_comboBox;
125 KComboBox *m_comboBox2;
126 QSpinBox *m_intSpinBox1;
127 QSpinBox *m_intSpinBox2;
128 Q3DateEdit *m_dateEdit1;
129 Q3DateEdit *m_dateEdit2;
130 KComboBox *m_dateCombo;
131 QLabel *m_rangeLabel;
132 KComboBox *m_lengthCombo;
135 inline int
136 CriteriaEditor::indexToRating( int index )
138 if ( index <= 9 && index >= 1 ) return index + 1;
139 if ( index == 0 ) return index;
140 return -1;
143 inline int
144 CriteriaEditor::ratingToIndex( int rating )
146 if ( rating <= 10 && rating >= 2 ) return rating - 1;
147 if ( rating == 0 ) return rating;
148 return -1;
151 #endif