summaryrefslogtreecommitdiff
path: root/noncore/settings/packagemanager/filterdlg.cpp
blob: 4924972f4a7d2d815b7080d635641e04d6f11fa1 (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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
                             This file is part of the Opie Project

                             Copyright (C)2004, 2005 Dan Williams <drw@handhelds.org>
              =.
            .=l.
           .>+-=
 _;:,     .>    :=|.         This program is free software; you can
.> <`_,   >  .   <=          redistribute it and/or  modify it under
:`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
.="- .-=="i,     .._         License as published by the Free Software
 - .   .-<_>     .<>         Foundation; either version 2 of the License,
     ._= =}       :          or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s.       This program is distributed in the hope that
     +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
    : ..    .:,     . . .    without even the implied warranty of
    =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ;      Library General Public License for more
++=   -.     .`     .:       details.
:     =  ...= . :.=-
 -.   .:....=;==+<;          You should have received a copy of the GNU
  -_. . .   )=.  =           Library General Public License along with
    --        :-=`           this library; see the file COPYING.LIB.
                             If not, write to the Free Software Foundation,
                             Inc., 59 Temple Place - Suite 330,
                             Boston, MA 02111-1307, USA.
*/

#include "filterdlg.h"

#include <qwhatsthis.h>

FilterDlg::FilterDlg( QWidget *parent, OPackageManager *pm, const QString &name,
               const QString &server, const QString &destination,
               OPackageManager::Status status, const QString &category )
    : QDialog( parent, QString::null, true, WStyle_ContextHelp )
{
    setCaption( tr( "Filter packages" ) );

    QVBoxLayout *layout = new QVBoxLayout( this );
    QScrollView *sv = new QScrollView( this );
    layout->addWidget( sv, 0, 0 );
    sv->setResizePolicy( QScrollView::AutoOneFit );
    sv->setFrameStyle( QFrame::NoFrame );
    QWidget *container = new QWidget( sv->viewport() );
    sv->addChild( container );
    layout = new QVBoxLayout( container, 4, 4 );

    // Category
    m_categoryCB = new QCheckBox( tr( "Category:" ), container );
    QWhatsThis::add( m_categoryCB, tr( "Tap here to filter package list by application category." ) );
    connect( m_categoryCB, SIGNAL(toggled(bool)), this, SLOT(slotCategorySelected(bool)) );
    m_category = new QComboBox( container );
    QWhatsThis::add( m_category, tr( "Select the application category to filter by here." ) );
    m_category->insertStringList( pm->categories() );
    initItem( m_category, m_categoryCB, category );
    layout->addWidget( m_categoryCB );
    layout->addWidget( m_category );

    // Package name
    m_nameCB = new QCheckBox( tr( "Names containing:" ), container );
    QWhatsThis::add( m_nameCB, tr( "Tap here to filter package list by package name." ) );
    connect( m_nameCB, SIGNAL(toggled(bool)), this, SLOT(slotNameSelected(bool)) );
    m_name = new QLineEdit( name, container );
    QWhatsThis::add( m_name, tr( "Enter the package name to filter by here." ) );
    if ( !name.isNull() )
        m_nameCB->setChecked( true );
    m_name->setEnabled( !name.isNull() );
    layout->addWidget( m_nameCB );
    layout->addWidget( m_name );

    // Status
    m_statusCB = new QCheckBox( tr( "With the status:" ), container );
    QWhatsThis::add( m_statusCB, tr( "Tap here to filter package list by the package status." ) );
    connect( m_statusCB, SIGNAL(toggled(bool)), this, SLOT(slotStatusSelected(bool)) );
    m_status = new QComboBox( container );
    QWhatsThis::add( m_status, tr( "Select the package status to filter by here." ) );
    connect( m_status, SIGNAL(activated(const QString&)), this, SLOT(slotStatusChanged(const QString&)) );
    QString currStatus;
    switch ( status )
    {
        case OPackageManager::All : currStatus = tr( "All" );
            break;
        case OPackageManager::Installed : currStatus = tr( "Installed" );
            break;
        case OPackageManager::NotInstalled : currStatus = tr( "Not installed" );
            break;
        case OPackageManager::Updated : currStatus = tr( "Updated" );
            break;
        default : currStatus = QString::null;
    };
    m_status->insertItem( tr( "All" ) );
    m_status->insertItem( tr( "Installed" ) );
    m_status->insertItem( tr( "Not installed" ) );
    m_status->insertItem( tr( "Updated" ) );
    initItem( m_status, m_statusCB, currStatus );
    layout->addWidget( m_statusCB );
    layout->addWidget( m_status );

    // Server
    m_serverCB = new QCheckBox( tr( "Available from the following server:" ), container );
    QWhatsThis::add( m_serverCB, tr( "Tap here to filter package list by source server." ) );
    connect( m_serverCB, SIGNAL(toggled(bool)), this, SLOT(slotServerSelected(bool)) );
    m_server = new QComboBox( container );
    QWhatsThis::add( m_server, tr( "Select the source server to filter by here." ) );
    m_server->insertStringList( pm->servers() );
    initItem( m_server, m_serverCB, server );
    layout->addWidget( m_serverCB );
    layout->addWidget( m_server );

    // Destination
    m_destCB = new QCheckBox( tr( "Installed on device at:" ), container );
    QWhatsThis::add( m_destCB, tr( "Tap here to filter package list by destination where the package is installed to on this device." ) );
    connect( m_destCB, SIGNAL(toggled(bool)), this, SLOT(slotDestSelected(bool)) );
    m_destination = new QComboBox( container );
    QWhatsThis::add( m_destination, tr( "Select the destination location to filter by here." ) );
    m_destination->insertStringList( pm->destinations() );
    initItem( m_destination, m_destCB, destination );
    layout->addWidget( m_destCB );
    layout->addWidget( m_destination );
}

void FilterDlg::initItem( QComboBox *comboBox, QCheckBox *checkBox, const QString &selection )
{
    if ( !selection.isNull() )
    {
        checkBox->setChecked( true );

        for ( int i = 0; i < comboBox->count(); i++ )
        {
            if ( comboBox->text( i ) == selection )
            {
                comboBox->setCurrentItem( i );
                return;
            }
        }
    }
    comboBox->setEnabled( !selection.isNull() );
}

void FilterDlg::slotNameSelected( bool selected )
{
    m_name->setEnabled( selected );
    m_name->setFocus();
}

void FilterDlg::slotServerSelected( bool selected )
{
    m_server->setEnabled( selected );
    m_server->setFocus();
}

void FilterDlg::slotDestSelected( bool selected )
{
    m_destination->setEnabled( selected );
    m_destination->setFocus();
}

void FilterDlg::slotStatusSelected( bool selected )
{
    m_status->setEnabled( selected );
    m_status->setFocus();

    if ( !selected && !m_destCB->isEnabled() )
    {
        // If status check box has been deselected and destination option was previously deselected
        // (because status == "Not installed"), re-enable destination option
        m_destCB->setEnabled( true );
        m_destination->setEnabled( true );
    }
    else if ( selected && m_destCB->isEnabled() && m_status->currentText() == tr( "Not installed" ) )
    {
        // If status check box has been selected and status == "Not installed", disable destination option
        m_destCB->setEnabled( false );
        m_destCB->setChecked( false );
        m_destination->setEnabled( false );
    }
}

void FilterDlg::slotStatusChanged( const QString &category )
{
    bool notInstalled = ( category == tr( "Not installed" ) );
    m_destCB->setEnabled( !notInstalled );
    m_destination->setEnabled( !notInstalled );
    if ( notInstalled )
        m_destCB->setChecked( false );
}

void FilterDlg::slotCategorySelected( bool selected )
{
    m_category->setEnabled( selected );
    m_category->setFocus();
}