summaryrefslogtreecommitdiff
path: root/noncore/settings/aqpkg/installdlgimpl.cpp
blob: 31be213355fa713e00229bf1326c9efc6ed98d72 (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
/***************************************************************************
                          installdlgimpl.cpp  -  description
                             -------------------
    begin                : Mon Aug 26 2002
    copyright            : (C) 2002 by Andy Qua
    email                : andy.qua@blueyonder.co.uk
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifdef QWS
#include <qpe/config.h>
#endif

#include <qmultilineedit.h>
#include <qdialog.h>
#include <qcombobox.h>
#include <qcheckbox.h>
#include <qpushbutton.h>


#include "datamgr.h"
#include "instoptionsimpl.h"
#include "destination.h"
#include "installdlgimpl.h"
#include "global.h"

InstallDlgImpl::InstallDlgImpl( vector<QString> &packageList, DataManager *dataManager, QWidget * parent, const char* name, bool modal, WFlags fl )
    : InstallDlg( parent, name, modal, fl )
{
    dataMgr = dataManager;
    vector<Destination>::iterator dit;

    QString defaultDest = "root";
#ifdef QWS
    Config cfg( "aqpkg" );
    cfg.setGroup( "settings" );
    defaultDest = cfg.readEntry( "dest", "root" );

    // Grab flags - Turn MAKE_LINKS on by default (if no flags found)
    flags = cfg.readNumEntry( "installFlags", MAKE_LINKS );
#else
	flags = 0;
#endif

    // Output text is read only
    output->setReadOnly( true );

    // setup destination data
    int defIndex = 0;
    int i;
    for ( i = 0 , dit = dataMgr->getDestinationList().begin() ; dit != dataMgr->getDestinationList().end() ; ++dit, ++i )
    {
        destination->insertItem( dit->getDestinationName() );
        if ( dit->getDestinationName() == defaultDest )
            defIndex = i;
    }

    destination->setCurrentItem( defIndex );

	vector<QString>::iterator it;
	// setup package data
	QString remove = "Remove\n";
	QString install = "\nInstall\n";
	QString upgrade = "\nUpgrade\n";
	for ( it = packageList.begin() ; it != packageList.end() ; ++it )
	{
		QString name = *it;
		if ( name.startsWith( "I" ) )
		{
			installList.push_back( name.mid(1) );
			install += "   " + name.mid(1) + "\n";
		}
		else if ( name.startsWith( "D" ) )
		{
			removeList.push_back( name.mid(1) );
			remove += "   " + name.mid(1) + "\n";
		}
		else if ( name.startsWith( "U" ) )
		{
			updateList.push_back( name.mid(1) );
			upgrade += "   " + name.mid(1) + "\n";
		}
	}

	output->setText( remove + install + upgrade );

    connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &)));
}

InstallDlgImpl::~InstallDlgImpl()
{
}

bool InstallDlgImpl :: showDlg()
{
	showMaximized();
	bool ret = exec();

	return ret;
}

void InstallDlgImpl :: optionsSelected()
{
	InstallOptionsDlgImpl opt( flags, this, "Option", true );
	opt.exec();

	// set options selected from dialog
    flags = 0;
    if ( opt.forceDepends->isChecked() )
        flags |= FORCE_DEPENDS;
    if ( opt.forceReinstall->isChecked() )
        flags |= FORCE_REINSTALL;
    if ( opt.forceRemove->isChecked() )
        flags |= FORCE_REMOVE;
    if ( opt.forceOverwrite->isChecked() )
        flags |= FORCE_OVERWRITE;
    if ( opt.makeLinks->isChecked() )
        flags |= MAKE_LINKS;

#ifdef QWS
    Config cfg( "aqpkg" );
    cfg.setGroup( "settings" );
    cfg.writeEntry( "installFlags", flags );
#endif
}

void InstallDlgImpl :: installSelected()
{
	if ( btnInstall->text() == "Close" )
	{
		done( 1 );
		return;
	}

	btnInstall->setEnabled( false );

    output->setText( "" );
    Destination *d = dataMgr->getDestination( destination->currentText() );
    QString dest = d->getDestinationName();
    QString destDir = d->getDestinationPath();

#ifdef QWS
    // Save settings
    Config cfg( "aqpkg" );
    cfg.setGroup( "settings" );
    cfg.writeEntry( "dest", dest );
#endif

    // First run through the remove list, then the install list then the upgrade list
	vector<QString>::iterator it;
    ipkg.setOption( "remove" );
    ipkg.setDestination( dest );
    ipkg.setDestinationDir( destDir );
    ipkg.setFlags( flags );
    for ( it = removeList.begin() ; it != removeList.end() ; ++it )
    {
        ipkg.setPackage( *it );
        ipkg.runIpkg();
    }
    
    ipkg.setOption( "install" );
    for ( it = installList.begin() ; it != installList.end() ; ++it )
    {
        ipkg.setPackage( *it );
        ipkg.runIpkg();
    }
    
    flags |= FORCE_REINSTALL;
    ipkg.setFlags( flags );
    for ( it = updateList.begin() ; it != updateList.end() ; ++it )
    {
        ipkg.setPackage( *it );
        ipkg.runIpkg();
    }

	btnInstall->setEnabled( true );
    btnInstall->setText( tr( "Close" ) );
}

void InstallDlgImpl :: displayText(const QString &text )
{
    QString t = output->text() + "\n" + text;
    output->setText( t );
    output->setCursorPosition( output->numLines(), 0 );
}