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

packageinfodlg.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 "packageinfodlg.h"
00032 #include "opackage.h"
00033 #include "opackagemanager.h"
00034 
00035 #include <opie2/oresource.h>
00036 #include <opie2/otabwidget.h>
00037 
00038 #include <qlayout.h>
00039 #include <qpushbutton.h>
00040 #include <qwhatsthis.h>
00041 
00042 PackageInfoDlg::PackageInfoDlg( QWidget *parent, OPackageManager *pm, const QString &package )
00043     : QWidget( 0l )
00044     , m_packman( pm )
00045     , m_information( this )
00046     , m_files( this )
00047     , m_retrieveFiles( 0l )
00048 {
00049     // Initialize UI
00050     if ( parent )
00051         parent->setCaption( package );
00052 
00053     QVBoxLayout *layout = new QVBoxLayout( this, 4, 2 );
00054 
00055     Opie::Ui::OTabWidget *tabWidget = new Opie::Ui::OTabWidget( this );
00056     layout->addWidget( tabWidget );
00057 
00058     // Information tab
00059     QWhatsThis::add( &m_information, tr( "This area contains information about the package." ) );
00060     m_information.reparent( tabWidget, QPoint( 0, 0 ) );
00061     m_information.setReadOnly( true );
00062     tabWidget->addTab( &m_information, "UtilsIcon", tr( "Information" ) );
00063 
00064     // Retrive package information
00065     m_package = m_packman->findPackage( package );
00066     if ( !m_package )
00067     {
00068         m_information.setText( tr( "Unable to retrieve package information." ) );
00069         return;
00070     }
00071 
00072     // Display package information
00073     if ( !m_package->information().isNull() )
00074         m_information.setText( m_package->information() );
00075     else
00076     {
00077         // Package information is not cached, retrieve it
00078         QStringList list( package );
00079         m_packman->executeCommand( OPackage::Info, list, QString::null,
00080                                    this, SLOT(slotInfo(const QString &)), true );
00081     }
00082 
00083     // Files tab (display only if package is installed)
00084     if ( !m_package->versionInstalled().isNull() )
00085     {
00086         QWidget *filesWidget = new QWidget( tabWidget );
00087         QVBoxLayout *filesLayout = new QVBoxLayout( filesWidget, 2, 2 );
00088         QWhatsThis::add( &m_files, tr( "This area contains a list of files contained in this package." ) );
00089         m_files.reparent( filesWidget, QPoint( 0, 0 ) );
00090         m_files.setReadOnly( true );
00091         filesLayout->addWidget( &m_files );
00092 
00093         // If file list is already cached, display
00094         if ( !m_package->files().isNull() )
00095             m_files.setText( m_package->files() );
00096         else
00097         {
00098             m_retrieveFiles = new QPushButton( Opie::Core::OResource::loadPixmap( "packagemanager/apply",
00099                                                Opie::Core::OResource::SmallIcon ), tr( "Retrieve file list" ),
00100                                                filesWidget );
00101             QWhatsThis::add( m_retrieveFiles, tr( "Tap here to retrieve list of files contained in this package." ) );
00102             filesLayout->addWidget( m_retrieveFiles );
00103             connect( m_retrieveFiles, SIGNAL(clicked()), this, SLOT(slotBtnFileScan()) );
00104         }
00105 
00106         tabWidget->addTab( filesWidget, "binary", tr( "File list" ) );
00107         tabWidget->setCurrentTab( tr( "Information" ) );
00108 
00109     }
00110     else
00111         m_files.hide();
00112 }
00113 
00114 PackageInfoDlg::~PackageInfoDlg()
00115 {
00116     if ( !m_package )
00117         return;
00118 
00119     // Cache package information
00120     if ( !m_information.text().isNull() )
00121         m_package->setInformation( m_information.text() );
00122 
00123     // Cache package file list
00124     if ( !m_files.text().isEmpty() )
00125         m_package->setFiles( m_files.text() );
00126 }
00127 
00128 void PackageInfoDlg::slotBtnFileScan()
00129 {
00130     m_files.clear();
00131 
00132     QStringList list( m_package->name() );
00133     m_packman->executeCommand( OPackage::Files, list, QString::null,
00134                                this, SLOT(slotFiles(const QString &)), true );
00135 
00136     if ( m_retrieveFiles )
00137         m_retrieveFiles->hide();
00138 }
00139 
00140 void PackageInfoDlg::slotInfo( const QString &info )
00141 {
00142     m_information.append( info );
00143 }
00144 
00145 void PackageInfoDlg::slotFiles( const QString &filelist )
00146 {
00147     QString str = filelist;
00148 
00149     // Skip first line of output ("Package xxx is installed...")
00150     if ( str.startsWith( "Package " ) )
00151         str = str.right( str.length() - str.find( '\n' ) - 1 );
00152 
00153     m_files.append( str );
00154 }

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