Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

filterdlg.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003 
00004                              Copyright (C)2004, 2005 Dan Williams <drw@handhelds.org>
00005               =.
00006             .=l.
00007            .>+-=
00008  _;:,     .>    :=|.         This program is free software; you can
00009 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00010 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00011 .="- .-=="i,     .._         License as published by the Free Software
00012  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00013      ._= =}       :          or (at your option) any later version.
00014     .%`+i>       _;_.
00015     .i_,=:_.      -<s.       This program is distributed in the hope that
00016      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00017     : ..    .:,     . . .    without even the implied warranty of
00018     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00019   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00020 ..}^=.=       =       ;      Library General Public License for more
00021 ++=   -.     .`     .:       details.
00022 :     =  ...= . :.=-
00023  -.   .:....=;==+<;          You should have received a copy of the GNU
00024   -_. . .   )=.  =           Library General Public License along with
00025     --        :-=`           this library; see the file COPYING.LIB.
00026                              If not, write to the Free Software Foundation,
00027                              Inc., 59 Temple Place - Suite 330,
00028                              Boston, MA 02111-1307, USA.
00029 */
00030 
00031 #include "filterdlg.h"
00032 
00033 #include <qwhatsthis.h>
00034 
00035 FilterDlg::FilterDlg( QWidget *parent, OPackageManager *pm, const QString &name,
00036                const QString &server, const QString &destination,
00037                OPackageManager::Status status, const QString &category )
00038     : QDialog( parent, QString::null, true, WStyle_ContextHelp )
00039 {
00040     setCaption( tr( "Filter packages" ) );
00041 
00042     QVBoxLayout *layout = new QVBoxLayout( this );
00043     QScrollView *sv = new QScrollView( this );
00044     layout->addWidget( sv, 0, 0 );
00045     sv->setResizePolicy( QScrollView::AutoOneFit );
00046     sv->setFrameStyle( QFrame::NoFrame );
00047     QWidget *container = new QWidget( sv->viewport() );
00048     sv->addChild( container );
00049     layout = new QVBoxLayout( container, 4, 4 );
00050 
00051     // Category
00052     m_categoryCB = new QCheckBox( tr( "Category:" ), container );
00053     QWhatsThis::add( m_categoryCB, tr( "Tap here to filter package list by application category." ) );
00054     connect( m_categoryCB, SIGNAL(toggled(bool)), this, SLOT(slotCategorySelected(bool)) );
00055     m_category = new QComboBox( container );
00056     QWhatsThis::add( m_category, tr( "Select the application category to filter by here." ) );
00057     m_category->insertStringList( pm->categories() );
00058     initItem( m_category, m_categoryCB, category );
00059     layout->addWidget( m_categoryCB );
00060     layout->addWidget( m_category );
00061 
00062     // Package name
00063     m_nameCB = new QCheckBox( tr( "Names containing:" ), container );
00064     QWhatsThis::add( m_nameCB, tr( "Tap here to filter package list by package name." ) );
00065     connect( m_nameCB, SIGNAL(toggled(bool)), this, SLOT(slotNameSelected(bool)) );
00066     m_name = new QLineEdit( name, container );
00067     QWhatsThis::add( m_name, tr( "Enter the package name to filter by here." ) );
00068     if ( !name.isNull() )
00069         m_nameCB->setChecked( true );
00070     m_name->setEnabled( !name.isNull() );
00071     layout->addWidget( m_nameCB );
00072     layout->addWidget( m_name );
00073 
00074     // Status
00075     m_statusCB = new QCheckBox( tr( "With the status:" ), container );
00076     QWhatsThis::add( m_statusCB, tr( "Tap here to filter package list by the package status." ) );
00077     connect( m_statusCB, SIGNAL(toggled(bool)), this, SLOT(slotStatusSelected(bool)) );
00078     m_status = new QComboBox( container );
00079     QWhatsThis::add( m_status, tr( "Select the package status to filter by here." ) );
00080     connect( m_status, SIGNAL(activated(const QString&)), this, SLOT(slotStatusChanged(const QString&)) );
00081     QString currStatus;
00082     switch ( status )
00083     {
00084         case OPackageManager::All : currStatus = tr( "All" );
00085             break;
00086         case OPackageManager::Installed : currStatus = tr( "Installed" );
00087             break;
00088         case OPackageManager::NotInstalled : currStatus = tr( "Not installed" );
00089             break;
00090         case OPackageManager::Updated : currStatus = tr( "Updated" );
00091             break;
00092         default : currStatus = QString::null;
00093     };
00094     m_status->insertItem( tr( "All" ) );
00095     m_status->insertItem( tr( "Installed" ) );
00096     m_status->insertItem( tr( "Not installed" ) );
00097     m_status->insertItem( tr( "Updated" ) );
00098     initItem( m_status, m_statusCB, currStatus );
00099     layout->addWidget( m_statusCB );
00100     layout->addWidget( m_status );
00101 
00102     // Server
00103     m_serverCB = new QCheckBox( tr( "Available from the following server:" ), container );
00104     QWhatsThis::add( m_serverCB, tr( "Tap here to filter package list by source server." ) );
00105     connect( m_serverCB, SIGNAL(toggled(bool)), this, SLOT(slotServerSelected(bool)) );
00106     m_server = new QComboBox( container );
00107     QWhatsThis::add( m_server, tr( "Select the source server to filter by here." ) );
00108     m_server->insertStringList( pm->servers() );
00109     initItem( m_server, m_serverCB, server );
00110     layout->addWidget( m_serverCB );
00111     layout->addWidget( m_server );
00112 
00113     // Destination
00114     m_destCB = new QCheckBox( tr( "Installed on device at:" ), container );
00115     QWhatsThis::add( m_destCB, tr( "Tap here to filter package list by destination where the package is installed to on this device." ) );
00116     connect( m_destCB, SIGNAL(toggled(bool)), this, SLOT(slotDestSelected(bool)) );
00117     m_destination = new QComboBox( container );
00118     QWhatsThis::add( m_destination, tr( "Select the destination location to filter by here." ) );
00119     m_destination->insertStringList( pm->destinations() );
00120     initItem( m_destination, m_destCB, destination );
00121     layout->addWidget( m_destCB );
00122     layout->addWidget( m_destination );
00123 }
00124 
00125 void FilterDlg::initItem( QComboBox *comboBox, QCheckBox *checkBox, const QString &selection )
00126 {
00127     if ( !selection.isNull() )
00128     {
00129         checkBox->setChecked( true );
00130 
00131         for ( int i = 0; i < comboBox->count(); i++ )
00132         {
00133             if ( comboBox->text( i ) == selection )
00134             {
00135                 comboBox->setCurrentItem( i );
00136                 return;
00137             }
00138         }
00139     }
00140     comboBox->setEnabled( !selection.isNull() );
00141 }
00142 
00143 void FilterDlg::slotNameSelected( bool selected )
00144 {
00145     m_name->setEnabled( selected );
00146     m_name->setFocus();
00147 }
00148 
00149 void FilterDlg::slotServerSelected( bool selected )
00150 {
00151     m_server->setEnabled( selected );
00152     m_server->setFocus();
00153 }
00154 
00155 void FilterDlg::slotDestSelected( bool selected )
00156 {
00157     m_destination->setEnabled( selected );
00158     m_destination->setFocus();
00159 }
00160 
00161 void FilterDlg::slotStatusSelected( bool selected )
00162 {
00163     m_status->setEnabled( selected );
00164     m_status->setFocus();
00165 
00166     if ( !selected && !m_destCB->isEnabled() )
00167     {
00168         // If status check box has been deselected and destination option was previously deselected
00169         // (because status == "Not installed"), re-enable destination option
00170         m_destCB->setEnabled( true );
00171         m_destination->setEnabled( true );
00172     }
00173     else if ( selected && m_destCB->isEnabled() && m_status->currentText() == tr( "Not installed" ) )
00174     {
00175         // If status check box has been selected and status == "Not installed", disable destination option
00176         m_destCB->setEnabled( false );
00177         m_destCB->setChecked( false );
00178         m_destination->setEnabled( false );
00179     }
00180 }
00181 
00182 void FilterDlg::slotStatusChanged( const QString &category )
00183 {
00184     bool notInstalled = ( category == tr( "Not installed" ) );
00185     m_destCB->setEnabled( !notInstalled );
00186     m_destination->setEnabled( !notInstalled );
00187     if ( notInstalled )
00188         m_destCB->setChecked( false );
00189 }
00190 
00191 void FilterDlg::slotCategorySelected( bool selected )
00192 {
00193     m_category->setEnabled( selected );
00194     m_category->setFocus();
00195 }

Generated on Sat Nov 5 16:17:56 2005 for OPIE by  doxygen 1.4.2