summaryrefslogtreecommitdiff
path: root/noncore/settings/packagemanager/packageinfodlg.cpp
blob: 3eef93931e5a20ebfdd76159d3d93cfeff0cfcc6 (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
/*
                    This file is part of the OPIE Project

               =.            Copyright (c)  2003 Dan Williams <drw@handhelds.org>
      .=l.
     .>+-=
_;:,   .>  :=|.         This file is free software; you can
.> <`_,  > .  <=          redistribute it and/or modify it under
:`=1 )Y*s>-.--  :           the terms of the GNU 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 file 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 General
..}^=.=    =    ;      Public License for more details.
++=  -.   .`   .:
:   = ...= . :.=-        You should have received a copy of the GNU
-.  .:....=;==+<;          General Public License along with this file;
 -_. . .  )=. =           see the file COPYING. If not, write to the
  --    :-=`           Free Software Foundation, Inc.,
                             59 Temple Place - Suite 330,
                             Boston, MA 02111-1307, USA.

*/

#include "packageinfodlg.h"
#include "opackage.h"
#include "opackagemanager.h"

#include <opie2/otabwidget.h>

#include <qpe/resource.h>

#include <qlayout.h>
#include <qpushbutton.h>
#include <qwhatsthis.h>

PackageInfoDlg::PackageInfoDlg( QWidget *parent, OPackageManager *pm, const QString &package )
    : QWidget( 0l )
    , m_packman( pm )
    , m_information( this )
    , m_files( this )
    , m_retrieveFiles( 0l )
{
    // Initialize UI
    if ( parent )
        parent->setCaption( package );

    QVBoxLayout *layout = new QVBoxLayout( this, 4, 2 );

    Opie::Ui::OTabWidget *tabWidget = new Opie::Ui::OTabWidget( this );
    layout->addWidget( tabWidget );

    // Information tab
    QWhatsThis::add( &m_information, tr( "This area contains information about the package." ) );
    m_information.reparent( tabWidget, QPoint( 0, 0 ) );
    m_information.setReadOnly( true );
    tabWidget->addTab( &m_information, "UtilsIcon", tr( "Information" ) );

    // Retrive package information
    m_package = m_packman->findPackage( package );
    if ( !m_package )
    {
        m_information.setText( tr( "Unable to retrieve package information." ) );
        return;
    }

    // Display package information
    if ( !m_package->information().isNull() )
        m_information.setText( m_package->information() );
    else
    {
        // Package information is not cached, retrieve it
        QStringList list( package );
        m_packman->executeCommand( OPackage::Info, list, QString::null,
                                   this, SLOT(slotInfo(const QString &)), true );
    }

    // Files tab (display only if package is installed)
    if ( !m_package->versionInstalled().isNull() )
    {
        QWidget *filesWidget = new QWidget( tabWidget );
        QVBoxLayout *filesLayout = new QVBoxLayout( filesWidget, 2, 2 );
        QWhatsThis::add( &m_files, tr( "This area contains a list of files contained in this package." ) );
        m_files.reparent( filesWidget, QPoint( 0, 0 ) );
        m_files.setReadOnly( true );
        filesLayout->addWidget( &m_files );

        // If file list is already cached, display
        if ( !m_package->files().isNull() )
            m_files.setText( m_package->files() );
        else
        {
            m_retrieveFiles = new QPushButton( Resource::loadPixmap( "packagemanager/apply" ),
                                            tr( "Retrieve file list" ), filesWidget );
            QWhatsThis::add( m_retrieveFiles, tr( "Tap here to retrieve list of files contained in this package." ) );
            filesLayout->addWidget( m_retrieveFiles );
            connect( m_retrieveFiles, SIGNAL(clicked()), this, SLOT(slotBtnFileScan()) );
        }

        tabWidget->addTab( filesWidget, "binary", tr( "File list" ) );
        tabWidget->setCurrentTab( tr( "Information" ) );

    }
    else
        m_files.hide();
}

PackageInfoDlg::~PackageInfoDlg()
{
    if ( !m_package )
        return;

    // Cache package information
    if ( !m_information.text().isNull() )
        m_package->setInformation( m_information.text() );

    // Cache package file list
    if ( !m_files.text().isEmpty() )
        m_package->setFiles( m_files.text() );
}

void PackageInfoDlg::slotBtnFileScan()
{
    m_files.clear();

    QStringList list( m_package->name() );
    m_packman->executeCommand( OPackage::Files, list, QString::null,
                               this, SLOT(slotFiles(const QString &)), true );

    if ( m_retrieveFiles )
        m_retrieveFiles->hide();
}

void PackageInfoDlg::slotInfo( const QString &info )
{
    m_information.append( info );
}

void PackageInfoDlg::slotFiles( const QString &filelist )
{
    QString str = filelist;

    // Skip first line of output ("Package xxx is installed...")
    if ( str.startsWith( "Package " ) )
        str = str.right( str.length() - str.find( '\n' ) - 1 );

    m_files.append( str );
}