Diffstat (limited to 'core/launcher/packageslave.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/launcher/packageslave.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/core/launcher/packageslave.cpp b/core/launcher/packageslave.cpp new file mode 100644 index 0000000..4f149a5 --- a/dev/null +++ b/core/launcher/packageslave.cpp | |||
@@ -0,0 +1,97 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "packageslave.h" | ||
22 | |||
23 | #include <qpe/process.h> | ||
24 | #include <qpe/qcopenvelope_qws.h> | ||
25 | |||
26 | #include <qdatastream.h> | ||
27 | #include <qcopchannel_qws.h> | ||
28 | |||
29 | #include <unistd.h> | ||
30 | |||
31 | PackageSlave::PackageSlave( QObject *parent, char* name ) | ||
32 | : QObject( parent, name ), packageChannel( 0 ) | ||
33 | { | ||
34 | // setup qcop channel | ||
35 | packageChannel = new QCopChannel( "QPE/Package", this ); | ||
36 | connect( packageChannel, SIGNAL( received(const QCString &, const QByteArray &) ), | ||
37 | this, SLOT( qcopMessage( const QCString &, const QByteArray &) ) ); | ||
38 | } | ||
39 | |||
40 | void PackageSlave::qcopMessage( const QCString &msg, const QByteArray &data ) | ||
41 | { | ||
42 | QDataStream stream( data, IO_ReadOnly ); | ||
43 | |||
44 | if ( msg == "installPackage(QString)" ) { | ||
45 | QString file; | ||
46 | stream >> file; | ||
47 | installPackage( file ); | ||
48 | } | ||
49 | else if ( msg == "removePackage(QString)" ) { | ||
50 | QString file; | ||
51 | stream >> file; | ||
52 | removePackage( file ); | ||
53 | } | ||
54 | } | ||
55 | |||
56 | void PackageSlave::installPackage( const QString &package ) | ||
57 | { | ||
58 | Process proc( QStringList() << "ipkg" << "install" << package ); | ||
59 | |||
60 | sendReply( "installStarted(QString)", package ); | ||
61 | |||
62 | QString output; | ||
63 | if ( proc.exec( "", output ) ) { | ||
64 | sendReply( "installDone(QString)", package ); | ||
65 | } | ||
66 | else { | ||
67 | sendReply( "installFailed(QString)", package ); | ||
68 | } | ||
69 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | ||
70 | QString lf = QString::null; | ||
71 | e << lf; | ||
72 | unlink( package ); | ||
73 | } | ||
74 | |||
75 | void PackageSlave::removePackage( const QString &package ) | ||
76 | { | ||
77 | Process proc( QStringList() << "ipkg" << "remove" << package ); | ||
78 | |||
79 | sendReply( "removeStarted(QString)", package ); | ||
80 | |||
81 | QString output; | ||
82 | if ( proc.exec( "", output ) ) { | ||
83 | sendReply( "removeDone(QString)", package ); | ||
84 | } | ||
85 | else { | ||
86 | sendReply( "removeFailed(QString)", package ); | ||
87 | } | ||
88 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | ||
89 | QString lf = QString::null; | ||
90 | e << lf; | ||
91 | } | ||
92 | |||
93 | void PackageSlave::sendReply( const QCString& msg, const QString& arg ) | ||
94 | { | ||
95 | QCopEnvelope e( "QPE/Desktop", msg ); | ||
96 | e << arg; | ||
97 | } | ||