summaryrefslogtreecommitdiff
path: root/noncore/unsupported/oipkg/pmipkg.cpp
Unidiff
Diffstat (limited to 'noncore/unsupported/oipkg/pmipkg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/oipkg/pmipkg.cpp183
1 files changed, 183 insertions, 0 deletions
diff --git a/noncore/unsupported/oipkg/pmipkg.cpp b/noncore/unsupported/oipkg/pmipkg.cpp
new file mode 100644
index 0000000..528365e
--- a/dev/null
+++ b/noncore/unsupported/oipkg/pmipkg.cpp
@@ -0,0 +1,183 @@
1#include "pmipkg.h"
2#include "pkdesc.h"
3#include "pkfind.h"
4#include "pksettings.h"
5#include "package.h"
6#include "packagelistitem.h"
7
8#include <qpe/process.h>
9#include <qpe/resource.h>
10#include <qpe/stringutil.h>
11#include <qpe/qcopenvelope_qws.h>
12#include <qdir.h>
13#include <qfile.h>
14#include <qmultilineedit.h>
15#include <qstring.h>
16#include <qtextstream.h>
17#include <qtextview.h>
18
19#include <stdlib.h>
20#include <unistd.h>
21
22#include "mainwindow.h"
23#include "runwindow.h"
24
25
26PmIpkg::PmIpkg( PackageManagerSettings* s, QWidget* p, const char * name, WFlags f )
27 : RunWindow ( p, name, f )
28 //: QObject ( p )
29{
30 settings = s;
31
32 linkDest = new QCopChannel( "QPE/MakeLinks", this );
33 connect( linkDest, SIGNAL(received(const QCString &, const QByteArray &)),
34 this, SLOT(linkDestination( const QString &, const QString&)) );
35}
36
37PmIpkg::~PmIpkg()
38{
39}
40
41int PmIpkg::runIpkg(const QString& args)
42{
43 pvDebug(4,"PmIpkg::runIpkg");
44 QString cmd = "/usr/bin/ipkg ";
45 cmd += " -dest "+settings->getDestinationName();
46 cmd += " -force-defaults ";
47
48 outPut->setText( outPut->text()+"<br><br>Starting to "+ args+"<br>\n");
49 QString redirect = "/tmp/ipkg.pipe";
50 cmd += args+" | tee "+redirect+" 2>&1&";
51
52 outPut->setText( outPut->text() + "running:<br>\n"+cmd+"<br>\n" );
53 pvDebug( 0, "Execute >"+cmd+"<" );
54 int r = system(cmd.latin1());
55 QFile f( redirect );
56 if ( f.open(IO_ReadOnly) ) {
57 QTextStream t( &f );
58 QString fp;
59 while ( !t.eof() )
60 {
61 outPut->setText( outPut->text() + t.readLine() +"\n<br>" );
62 }
63 }
64 f.close();
65 outPut->setText( outPut->text() + "\n<br><br>Finished!");
66 outPut->setContentsPos(0,outPut->contentsHeight());
67
68 if ( r == 0 )
69 {
70 QString param = args.left( args.find(" ") );
71 QString file = args.right( args.length() - args.find(" ") );
72 if ( param == "install" && settings->createLinks() )
73 makeLinks( file);
74 }
75
76 return r;
77}
78
79void PmIpkg::makeLinks(QString file)
80{
81 outPut->setText( outPut->text() + "<br>creating links<br>" );
82 QString dest = settings->getDestinationUrl();
83 system(("ipkg -d "+dest+" files "+file+"> /tmp/oipkg.pipe").latin1());
84 QFile f( "/tmp/oipkg.pipe" );
85 if ( ! f.open(IO_ReadOnly) )return;
86 QTextStream t( &f );
87 QString fp;
88 while ( !t.eof() )
89 {
90 processLinkDir( t.readLine(), dest );
91 }
92 f.close();
93}
94
95void PmIpkg::processLinkDir( QString file, QString dest )
96{
97 QString destFile = file.right( file.length() - dest.length() );
98 QFileInfo fileInfo( file );
99 if ( fileInfo.isFile() )
100 {
101 const char *instFile = strdup( (file).ascii() );
102 const char *linkFile = strdup( (destFile).ascii());
103 outPut->setText( outPut->text() + "linking: "+file+" -> "+destFile );
104 symlink( instFile, linkFile );
105 }
106 if ( fileInfo.isDir() )
107 {
108 QDir destDir( destFile );
109 destDir.mkdir( destFile, true );
110 QDir d( file );
111 d.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks );
112
113 const QFileInfoList *list = d.entryInfoList();
114 QFileInfoListIterator it( *list );
115 QFileInfo *fi;
116 while ( (fi=it.current()) ) {
117 processLinkDir( fi->absFilePath(), dest );
118 ++it;
119 }
120 }
121}
122
123void PmIpkg::commit( PackageList pl )
124 {
125 showMaximized();
126 exec();
127 outPut->setText( "<b>Starting...</b><br>\n");
128 QStringList to_remove, to_install;
129
130 QString rem="To remove:<br>\n";
131 QString inst="To install:<br>\n";;
132 for( Package *pack = pl.first();pack ; (pack = pl.next()) )
133 {
134 if ( pack && (pack->name() != "") && pack)
135 {
136 if ( pack->toInstall() )
137 {
138 to_install.append( pack->name() );
139 inst += pack->name()+"\n";
140 }
141 if ( pack->toRemove() )
142 {
143 to_remove.append( pack->name() );
144 rem += pack->name()+"\n";
145 }
146 }
147 }
148
149 outPut->setText( outPut->text()+inst+rem);
150 bool ok=TRUE;
151
152 qDebug("to remove=%i; to install=%i",to_remove.count(),to_install.count());
153
154 int jobs = to_remove.count()+to_install.count();
155 if ( jobs < 1 ) return;
156
157 if ( to_remove.count() )
158 for (QStringList::ConstIterator it=to_remove.begin(); it!=to_remove.end(); ++it)
159 if ( runIpkg("remove " + *it) != 0 ) ok = false;
160 if ( to_install.count() )
161 for (QStringList::ConstIterator it=to_install.begin(); it!=to_install.end(); ++it)
162 if ( runIpkg("install " + *it) != 0 ) ok = false;
163
164 // ##### If we looked in the list of files, we could send out accurate
165 // ##### messages. But we don't bother yet, and just do an "all".
166 QCopEnvelope e("QPE/System", "linkChanged(QString)");
167 QString lf = QString::null;
168 e << lf;
169}
170
171void PmIpkg::linkDestination( QString src, QString dest )
172{
173 QDir d( src );
174 d.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks );
175 if (! d.exists() ) return;
176 const QFileInfoList *list = d.entryInfoList();
177 QFileInfoListIterator it( *list );
178 QFileInfo *fi;
179 while ( (fi=it.current()) ) {
180 processLinkDir( fi->absFilePath(), dest );
181 ++it;
182 }
183}