summaryrefslogtreecommitdiff
authordrw <drw>2004-09-09 14:15:52 (UTC)
committer drw <drw>2004-09-09 14:15:52 (UTC)
commit317734f41201bf25fa3a1b38c2867bb9557053b9 (patch) (unidiff)
tree7ce5e9d735483415f42b15ae6939e37e8fc35a0c
parent4e798036b423bcb8800f125357591e48b84594c8 (diff)
downloadopie-317734f41201bf25fa3a1b38c2867bb9557053b9.zip
opie-317734f41201bf25fa3a1b38c2867bb9557053b9.tar.gz
opie-317734f41201bf25fa3a1b38c2867bb9557053b9.tar.bz2
Fix for too much verbosity while performing ipkg functions. Thanks to Seb for fix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/packagemanager/oipkg.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/noncore/settings/packagemanager/oipkg.cpp b/noncore/settings/packagemanager/oipkg.cpp
index eca5861..1978ad5 100644
--- a/noncore/settings/packagemanager/oipkg.cpp
+++ b/noncore/settings/packagemanager/oipkg.cpp
@@ -1,244 +1,246 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2003 Dan Williams <drw@handhelds.org> 4              Copyright (c) 2003 Dan Williams <drw@handhelds.org>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#include "oipkg.h" 32#include "oipkg.h"
33 33
34#include <qdir.h> 34#include <qdir.h>
35#include <qfile.h> 35#include <qfile.h>
36#include <qtextstream.h> 36#include <qtextstream.h>
37 37
38#include <stdlib.h> 38#include <stdlib.h>
39 39
40const QString IPKG_CONF = "/etc/ipkg.conf"; // Fully-qualified name of Ipkg primary configuration file 40const QString IPKG_CONF = "/etc/ipkg.conf"; // Fully-qualified name of Ipkg primary configuration file
41const QString IPKG_CONF_DIR = "/etc/ipkg"; // Directory of secondary Ipkg configuration files 41const QString IPKG_CONF_DIR = "/etc/ipkg"; // Directory of secondary Ipkg configuration files
42const QString IPKG_PKG_PATH = "/usr/lib/ipkg/lists"; // Directory containing server package lists 42const QString IPKG_PKG_PATH = "/usr/lib/ipkg/lists"; // Directory containing server package lists
43const QString IPKG_STATUS_PATH = "usr/lib/ipkg/status"; // Destination status file location 43const QString IPKG_STATUS_PATH = "usr/lib/ipkg/status"; // Destination status file location
44 44
45OIpkg *oipkg; 45OIpkg *oipkg;
46 46
47// Ipkg callback functions 47// Ipkg callback functions
48 48
49int fsignalIpkgMessage( ipkg_conf_t */*conf*/, message_level_t /*level*/, char *msg ) 49int fsignalIpkgMessage( ipkg_conf_t *conf, message_level_t level, char *msg )
50{ 50{
51 oipkg->ipkgMessage( msg ); 51 if ( conf && ( conf->verbosity < level ) )
52 return 0; 52 return 0;
53 else
54 oipkg->ipkgMessage( msg );
53} 55}
54 56
55char *fIpkgResponse( char */*question*/ ) 57char *fIpkgResponse( char */*question*/ )
56{ 58{
57 return 0x0; 59 return 0x0;
58} 60}
59 61
60int fIpkgStatus( char */*name*/, int /*status*/, char *desc, void */*userdata*/ ) 62int fIpkgStatus( char */*name*/, int /*status*/, char *desc, void */*userdata*/ )
61{ 63{
62 oipkg->ipkgStatus( desc ); 64 oipkg->ipkgStatus( desc );
63 return 0; 65 return 0;
64} 66}
65 67
66int fIpkgFiles( char */*name*/, char *desc, char */*version*/, pkg_state_status_t /*status*/, 68int fIpkgFiles( char */*name*/, char *desc, char */*version*/, pkg_state_status_t /*status*/,
67 void */*userdata*/ ) 69 void */*userdata*/ )
68{ 70{
69 oipkg->ipkgList( desc ); 71 oipkg->ipkgList( desc );
70 return 0; 72 return 0;
71} 73}
72 74
73OIpkg::OIpkg( Config *config, QObject *parent, const char *name ) 75OIpkg::OIpkg( Config *config, QObject *parent, const char *name )
74 : QObject( parent, name ) 76 : QObject( parent, name )
75 , m_config( config ) 77 , m_config( config )
76 , m_confInfo( NULL ) 78 , m_confInfo( NULL )
77 , m_ipkgExecOptions( 0 ) 79 , m_ipkgExecOptions( 0 )
78 , m_ipkgExecVerbosity( 1 ) 80 , m_ipkgExecVerbosity( 1 )
79{ 81{
80 oipkg = this; 82 oipkg = this;
81 83
82 // Initialize libipkg 84 // Initialize libipkg
83 ipkg_init( &fsignalIpkgMessage, &fIpkgResponse, &m_ipkgArgs ); 85 ipkg_init( &fsignalIpkgMessage, &fIpkgResponse, &m_ipkgArgs );
84 86
85 // Default ipkg run-time arguments 87 // Default ipkg run-time arguments
86 m_ipkgArgs.noaction = false; 88 m_ipkgArgs.noaction = false;
87 m_ipkgArgs.force_defaults = true; 89 m_ipkgArgs.force_defaults = true;
88} 90}
89 91
90OIpkg::~OIpkg() 92OIpkg::~OIpkg()
91{ 93{
92 // Upon destruction, ensure that items in config list are deleted with list 94 // Upon destruction, ensure that items in config list are deleted with list
93 if ( m_confInfo ) 95 if ( m_confInfo )
94 m_confInfo->setAutoDelete( true ); 96 m_confInfo->setAutoDelete( true );
95 97
96 // Free up libipkg resources 98 // Free up libipkg resources
97 ipkg_deinit( &m_ipkgArgs ); 99 ipkg_deinit( &m_ipkgArgs );
98} 100}
99 101
100OConfItemList *OIpkg::configItems() 102OConfItemList *OIpkg::configItems()
101{ 103{
102 // Retrieve all configuration items 104 // Retrieve all configuration items
103 return filterConfItems(); 105 return filterConfItems();
104} 106}
105 107
106OConfItemList *OIpkg::servers() 108OConfItemList *OIpkg::servers()
107{ 109{
108 // Retrieve only servers 110 // Retrieve only servers
109 return filterConfItems( OConfItem::Source ); 111 return filterConfItems( OConfItem::Source );
110} 112}
111 113
112OConfItemList *OIpkg::destinations() 114OConfItemList *OIpkg::destinations()
113{ 115{
114 // Retrieve only destinations 116 // Retrieve only destinations
115 return filterConfItems( OConfItem::Destination ); 117 return filterConfItems( OConfItem::Destination );
116} 118}
117 119
118OConfItemList *OIpkg::options() 120OConfItemList *OIpkg::options()
119{ 121{
120 // Retrieve only destinations 122 // Retrieve only destinations
121 return filterConfItems( OConfItem::Option ); 123 return filterConfItems( OConfItem::Option );
122} 124}
123 125
124void OIpkg::setConfigItems( OConfItemList *configList ) 126void OIpkg::setConfigItems( OConfItemList *configList )
125{ 127{
126 if ( m_confInfo ) 128 if ( m_confInfo )
127 delete m_confInfo; 129 delete m_confInfo;
128 130
129 m_confInfo = configList; 131 m_confInfo = configList;
130 132
131 // Write out new /etc/ipkg.conf 133 // Write out new /etc/ipkg.conf
132 QFile confFile( IPKG_CONF ); 134 QFile confFile( IPKG_CONF );
133 if ( confFile.open( IO_WriteOnly ) ) 135 if ( confFile.open( IO_WriteOnly ) )
134 { 136 {
135 QTextStream confStream( &confFile ); 137 QTextStream confStream( &confFile );
136 confStream << "# Generated by Opie Package Manager\n\n"; 138 confStream << "# Generated by Opie Package Manager\n\n";
137 139
138 OConfItemListIterator it( *m_confInfo ); 140 OConfItemListIterator it( *m_confInfo );
139 for ( ; it.current(); ++it ) 141 for ( ; it.current(); ++it )
140 { 142 {
141 OConfItem *item = it.current(); 143 OConfItem *item = it.current();
142 144
143 // Only write out valid conf items 145 // Only write out valid conf items
144 if ( item->type() != OConfItem::NotDefined ) 146 if ( item->type() != OConfItem::NotDefined )
145 { 147 {
146 QString confLine; 148 QString confLine;
147 if ( !item->active() ) 149 if ( !item->active() )
148 confLine = "#"; 150 confLine = "#";
149 151
150 switch ( item->type() ) 152 switch ( item->type() )
151 { 153 {
152 case OConfItem::Source : confLine.append( "src " ); break; 154 case OConfItem::Source : confLine.append( "src " ); break;
153 case OConfItem::Destination : confLine.append( "dest " ); break; 155 case OConfItem::Destination : confLine.append( "dest " ); break;
154 case OConfItem::Option : confLine.append( "option " ); break; 156 case OConfItem::Option : confLine.append( "option " ); break;
155 case OConfItem::Arch : confLine.append( "arch " ); break; 157 case OConfItem::Arch : confLine.append( "arch " ); break;
156 default : break; 158 default : break;
157 }; 159 };
158 160
159 confStream << confLine << " " << item->name() << " " << item->value() << "\n"; 161 confStream << confLine << " " << item->name() << " " << item->value() << "\n";
160 } 162 }
161 } 163 }
162 164
163 confFile.close(); 165 confFile.close();
164 } 166 }
165 else 167 else
166 { 168 {
167 // Problem writing to /etc/ipkg.conf, exit before removing other conf files 169 // Problem writing to /etc/ipkg.conf, exit before removing other conf files
168 return; 170 return;
169 } 171 }
170 172
171 // Delete /etc/ipkg/*.conf files (/etc/ipkg.conf should now have all settings 173 // Delete /etc/ipkg/*.conf files (/etc/ipkg.conf should now have all settings
172 QStringList confFiles; 174 QStringList confFiles;
173 QDir confDir( IPKG_CONF_DIR ); 175 QDir confDir( IPKG_CONF_DIR );
174 if ( confDir.exists() ) 176 if ( confDir.exists() )
175 { 177 {
176 confDir.setNameFilter( "*.conf" ); 178 confDir.setNameFilter( "*.conf" );
177 confDir.setFilter( QDir::Files ); 179 confDir.setFilter( QDir::Files );
178 confFiles = confDir.entryList( "*.conf", QDir::Files ); 180 confFiles = confDir.entryList( "*.conf", QDir::Files );
179 181
180 QStringList::Iterator lastFile = confFiles.end(); 182 QStringList::Iterator lastFile = confFiles.end();
181 for ( QStringList::Iterator it = confFiles.begin(); it != lastFile; ++it ) 183 for ( QStringList::Iterator it = confFiles.begin(); it != lastFile; ++it )
182 { 184 {
183 // Create absolute file path if necessary 185 // Create absolute file path if necessary
184 QString absFile = (*it); 186 QString absFile = (*it);
185 if ( !absFile.startsWith( "/" ) ) 187 if ( !absFile.startsWith( "/" ) )
186 absFile.prepend( QString( IPKG_CONF_DIR ) + "/" ); 188 absFile.prepend( QString( IPKG_CONF_DIR ) + "/" );
187 189
188 // Delete file 190 // Delete file
189 QFile::remove( absFile ); 191 QFile::remove( absFile );
190 } 192 }
191 } 193 }
192 194
193 // Reinitialize libipkg to pick up new configuration 195 // Reinitialize libipkg to pick up new configuration
194 ipkg_deinit( &m_ipkgArgs ); 196 ipkg_deinit( &m_ipkgArgs );
195 ipkg_init( &fsignalIpkgMessage, &fIpkgResponse, &m_ipkgArgs ); 197 ipkg_init( &fsignalIpkgMessage, &fIpkgResponse, &m_ipkgArgs );
196 m_ipkgArgs.noaction = false; 198 m_ipkgArgs.noaction = false;
197 m_ipkgArgs.force_defaults = true; 199 m_ipkgArgs.force_defaults = true;
198} 200}
199 201
200void OIpkg::saveSettings() 202void OIpkg::saveSettings()
201{ 203{
202 // Save Ipkg execution options to application configuration file 204 // Save Ipkg execution options to application configuration file
203 if ( m_config ) 205 if ( m_config )
204 { 206 {
205 m_config->setGroup( "Ipkg" ); 207 m_config->setGroup( "Ipkg" );
206 m_config->writeEntry( "ExecOptions", m_ipkgExecOptions ); 208 m_config->writeEntry( "ExecOptions", m_ipkgExecOptions );
207 m_config->writeEntry( "Verbosity", m_ipkgExecVerbosity ); 209 m_config->writeEntry( "Verbosity", m_ipkgExecVerbosity );
208 } 210 }
209} 211}
210 212
211OPackageList *OIpkg::availablePackages( const QString &server ) 213OPackageList *OIpkg::availablePackages( const QString &server )
212{ 214{
213 // Load Ipkg configuration info if not already cached 215 // Load Ipkg configuration info if not already cached
214 if ( !m_confInfo ) 216 if ( !m_confInfo )
215 loadConfiguration(); 217 loadConfiguration();
216 218
217 // Build new server list (caller is responsible for deleting) 219 // Build new server list (caller is responsible for deleting)
218 OPackageList *pl = new OPackageList; 220 OPackageList *pl = new OPackageList;
219 221
220 // Open package list file 222 // Open package list file
221 QFile f( IPKG_PKG_PATH + "/" + server ); 223 QFile f( IPKG_PKG_PATH + "/" + server );
222 if ( !f.open( IO_ReadOnly ) ) 224 if ( !f.open( IO_ReadOnly ) )
223 return NULL; 225 return NULL;
224 QTextStream t( &f ); 226 QTextStream t( &f );
225 227
226 // Process all information in package list file 228 // Process all information in package list file
227 OPackage *package = NULL; 229 OPackage *package = NULL;
228 QString line = t.readLine(); 230 QString line = t.readLine();
229 while ( !t.eof() ) 231 while ( !t.eof() )
230 { 232 {
231 // Determine key/value pair 233 // Determine key/value pair
232 int pos = line.find( ':', 0 ); 234 int pos = line.find( ':', 0 );
233 QString key; 235 QString key;
234 if ( pos > -1 ) 236 if ( pos > -1 )
235 key = line.mid( 0, pos ); 237 key = line.mid( 0, pos );
236 else 238 else
237 key = QString::null; 239 key = QString::null;
238 QString value = line.mid( pos+2, line.length()-pos ); 240 QString value = line.mid( pos+2, line.length()-pos );
239 241
240 // Allocate new package and insert into list 242 // Allocate new package and insert into list
241 if ( package == NULL && !key.isEmpty() ) 243 if ( package == NULL && !key.isEmpty() )
242 { 244 {
243 package = new OPackage( value ); 245 package = new OPackage( value );
244 package->setSource( server ); 246 package->setSource( server );