Diffstat (limited to 'noncore/settings/packagemanager/filterdlg.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/packagemanager/filterdlg.cpp | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/noncore/settings/packagemanager/filterdlg.cpp b/noncore/settings/packagemanager/filterdlg.cpp new file mode 100644 index 0000000..2e48d5b --- a/dev/null +++ b/noncore/settings/packagemanager/filterdlg.cpp | |||
@@ -0,0 +1,179 @@ | |||
1 | /* | ||
2 | This file is part of the OPIE Project | ||
3 | |||
4 | =. Copyright (c) 2003 Dan Williams <drw@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This file is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This file is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
19 | ..}^=.= = ; Public License for more details. | ||
20 | ++= -. .` .: | ||
21 | : = ...= . :.=- You should have received a copy of the GNU | ||
22 | -. .:....=;==+<; General Public License along with this file; | ||
23 | -_. . . )=. = see the file COPYING. If not, write to the | ||
24 | -- :-=` Free Software Foundation, Inc., | ||
25 | 59 Temple Place - Suite 330, | ||
26 | Boston, MA 02111-1307, USA. | ||
27 | |||
28 | */ | ||
29 | |||
30 | #include "filterdlg.h" | ||
31 | |||
32 | FilterDlg::FilterDlg( QWidget *parent, OPackageManager *pm, const QString &name, | ||
33 | const QString &server, const QString &destination, | ||
34 | OPackageManager::Status status, const QString &category ) | ||
35 | : QDialog( parent, QString::null, true ) | ||
36 | { | ||
37 | setCaption( tr( "Filter packages" ) ); | ||
38 | |||
39 | QVBoxLayout *layout = new QVBoxLayout( this ); | ||
40 | QScrollView *sv = new QScrollView( this ); | ||
41 | layout->addWidget( sv, 0, 0 ); | ||
42 | sv->setResizePolicy( QScrollView::AutoOneFit ); | ||
43 | sv->setFrameStyle( QFrame::NoFrame ); | ||
44 | QWidget *container = new QWidget( sv->viewport() ); | ||
45 | sv->addChild( container ); | ||
46 | layout = new QVBoxLayout( container, 4, 4 ); | ||
47 | |||
48 | // Category | ||
49 | m_categoryCB = new QCheckBox( tr( "Category:" ), container ); | ||
50 | connect( m_categoryCB, SIGNAL(toggled(bool)), this, SLOT(slotCategorySelected(bool)) ); | ||
51 | m_category = new QComboBox( container ); | ||
52 | m_category->insertStringList( pm->categories() ); | ||
53 | initItem( m_category, m_categoryCB, category ); | ||
54 | layout->addWidget( m_categoryCB ); | ||
55 | layout->addWidget( m_category ); | ||
56 | |||
57 | // Package name | ||
58 | m_nameCB = new QCheckBox( tr( "Names containing:" ), container ); | ||
59 | connect( m_nameCB, SIGNAL(toggled(bool)), this, SLOT(slotNameSelected(bool)) ); | ||
60 | m_name = new QLineEdit( name, container ); | ||
61 | if ( !name.isNull() ) | ||
62 | m_nameCB->setChecked( true ); | ||
63 | m_name->setEnabled( !name.isNull() ); | ||
64 | layout->addWidget( m_nameCB ); | ||
65 | layout->addWidget( m_name ); | ||
66 | |||
67 | // Status | ||
68 | m_statusCB = new QCheckBox( tr( "With the status:" ), container ); | ||
69 | connect( m_statusCB, SIGNAL(toggled(bool)), this, SLOT(slotStatusSelected(bool)) ); | ||
70 | m_status = new QComboBox( container ); | ||
71 | connect( m_status, SIGNAL(activated(const QString &)), this, SLOT(slotStatusChanged(const QString &)) ); | ||
72 | QString currStatus; | ||
73 | switch ( status ) | ||
74 | { | ||
75 | case OPackageManager::All : currStatus = tr( "All" ); | ||
76 | break; | ||
77 | case OPackageManager::Installed : currStatus = tr( "Installed" ); | ||
78 | break; | ||
79 | case OPackageManager::NotInstalled : currStatus = tr( "Not installed" ); | ||
80 | break; | ||
81 | case OPackageManager::Updated : currStatus = tr( "Updated" ); | ||
82 | break; | ||
83 | default : currStatus = QString::null; | ||
84 | }; | ||
85 | m_status->insertItem( tr( "All" ) ); | ||
86 | m_status->insertItem( tr( "Installed" ) ); | ||
87 | m_status->insertItem( tr( "Not installed" ) ); | ||
88 | m_status->insertItem( tr( "Updated" ) ); | ||
89 | initItem( m_status, m_statusCB, currStatus ); | ||
90 | layout->addWidget( m_statusCB ); | ||
91 | layout->addWidget( m_status ); | ||
92 | |||
93 | // Server | ||
94 | m_serverCB = new QCheckBox( tr( "Available from the following server:" ), container ); | ||
95 | connect( m_serverCB, SIGNAL(toggled(bool)), this, SLOT(slotServerSelected(bool)) ); | ||
96 | m_server = new QComboBox( container ); | ||
97 | m_server->insertStringList( *(pm->servers()) ); | ||
98 | initItem( m_server, m_serverCB, server ); | ||
99 | layout->addWidget( m_serverCB ); | ||
100 | layout->addWidget( m_server ); | ||
101 | |||
102 | // Destination | ||
103 | m_destCB = new QCheckBox( tr( "Installed on device at:" ), container ); | ||
104 | connect( m_destCB, SIGNAL(toggled(bool)), this, SLOT(slotDestSelected(bool)) ); | ||
105 | m_destination = new QComboBox( container ); | ||
106 | m_destination->insertStringList( *(pm->destinations()) ); | ||
107 | initItem( m_destination, m_destCB, destination ); | ||
108 | layout->addWidget( m_destCB ); | ||
109 | layout->addWidget( m_destination ); | ||
110 | |||
111 | showMaximized(); | ||
112 | } | ||
113 | |||
114 | void FilterDlg::initItem( QComboBox *comboBox, QCheckBox *checkBox, const QString &selection ) | ||
115 | { | ||
116 | if ( !selection.isNull() ) | ||
117 | { | ||
118 | checkBox->setChecked( true ); | ||
119 | |||
120 | for ( int i = 0; i < comboBox->count(); i++ ) | ||
121 | { | ||
122 | if ( comboBox->text( i ) == selection ) | ||
123 | { | ||
124 | comboBox->setCurrentItem( i ); | ||
125 | return; | ||
126 | } | ||
127 | } | ||
128 | } | ||
129 | comboBox->setEnabled( !selection.isNull() ); | ||
130 | } | ||
131 | |||
132 | void FilterDlg::slotNameSelected( bool selected ) | ||
133 | { | ||
134 | m_name->setEnabled( selected ); | ||
135 | } | ||
136 | |||
137 | void FilterDlg::slotServerSelected( bool selected ) | ||
138 | { | ||
139 | m_server->setEnabled( selected ); | ||
140 | } | ||
141 | |||
142 | void FilterDlg::slotDestSelected( bool selected ) | ||
143 | { | ||
144 | m_destination->setEnabled( selected ); | ||
145 | } | ||
146 | |||
147 | void FilterDlg::slotStatusSelected( bool selected ) | ||
148 | { | ||
149 | m_status->setEnabled( selected ); | ||
150 | |||
151 | if ( !selected && !m_destCB->isEnabled() ) | ||
152 | { | ||
153 | // If status check box has been deselected and destination option was previously deselected | ||
154 | // (because status == "Not installed"), re-enable destination option | ||
155 | m_destCB->setEnabled( true ); | ||
156 | m_destination->setEnabled( true ); | ||
157 | } | ||
158 | else if ( selected && m_destCB->isEnabled() && m_status->currentText() == tr( "Not installed" ) ) | ||
159 | { | ||
160 | // If status check box has been selected and status == "Not installed", disable destination option | ||
161 | m_destCB->setEnabled( false ); | ||
162 | m_destCB->setChecked( false ); | ||
163 | m_destination->setEnabled( false ); | ||
164 | } | ||
165 | } | ||
166 | |||
167 | void FilterDlg::slotStatusChanged( const QString &category ) | ||
168 | { | ||
169 | bool notInstalled = ( category == tr( "Not installed" ) ); | ||
170 | m_destCB->setEnabled( !notInstalled ); | ||
171 | m_destination->setEnabled( !notInstalled ); | ||
172 | if ( notInstalled ) | ||
173 | m_destCB->setChecked( false ); | ||
174 | } | ||
175 | |||
176 | void FilterDlg::slotCategorySelected( bool selected ) | ||
177 | { | ||
178 | m_category->setEnabled( selected ); | ||
179 | } | ||