Vidalia 0.3.1
UpdateProcess.h
Go to the documentation of this file.
1/*
2** This file is part of Vidalia, and is subject to the license terms in the
3** LICENSE file, found in the top level directory of this distribution. If you
4** did not receive the LICENSE file with this file, you may obtain it from the
5** Vidalia source package distributed by the Vidalia Project at
6** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7** including this file, may be copied, modified, propagated, or distributed
8** except according to the terms described in the LICENSE file.
9*/
10
11#ifndef _UPDATEPROCESS_H
12#define _UPDATEPROCESS_H
13
14#include "PackageInfo.h"
15
16#include <QProcess>
17#include <QDateTime>
18#include <QStringList>
19#include <QUrl>
20
21
22class UpdateProcess : public QProcess
23{
24 Q_OBJECT
25
26public:
29 };
30
31 /** Default constructor.
32 */
33 UpdateProcess(QObject *parent = 0);
34
35 /** Begin a check for software updates that may be available for the
36 * software package specified by <b>bi</b>.
37 */
39
40 /** Instructs the software update process to install previously downloaded
41 * files for <b>bi</b>.
42 */
44
45 /** Returns true if the update process is currently in the middle of an
46 * operation, such as checking for or installing updates.
47 */
48 bool isRunning() const;
49
50 /** Sets the port to use as a SOCKS proxy to <b>port</b>. If <b>port</b> is
51 * set to 0, then no SOCKS proxy will be used when checking for updates.
52 */
53 void setSocksPort(quint16 port);
54
55 /** Return the time at which we should next check for available updates,
56 * given the last we checked was at <b>lastCheckedAt</b>.
57 */
58 static QDateTime nextCheckForUpdates(const QDateTime &lastCheckedAt);
59
60 /** Return true if we should check for available software udpates, given
61 * the last time we checked was at <b>lastCheckedAt</b>. The returned
62 * QDateTime will be in UTC.
63 */
64 static bool shouldCheckForUpdates(const QDateTime &lastCheckedAt);
65
66 /** Returns the preferred interval (in seconds) between executions of the
67 * Glider process to check for available software updates.
68 */
69 static int checkForUpdatesInterval();
70
71 /** Returns the path and filename of the software update executable.
72 */
73 static QString updateExecutable();
74
75 /** Returns the path in which the software update executable should write
76 * all of its state information.
77 */
78 static QString updateRepositoryDir();
79
80signals:
81 /** Emitted when the check for available software updates failed.
82 * <b>errmsg</b> contains a human-readable description of the problem
83 * encountered.
84 */
85 void checkForUpdatesFailed(QString errmsg);
86
87 /** Emitted while an updated package download is in progress. <b>url</b> is
88 * location of the update, <b>bytesReceived</b> is how many bytes have been
89 * downloaded so far and <b>bytesTotal</b> is the total size of the package
90 * being downloaded. */
91 void downloadProgress(QString url, int bytesReceived, int bytesTotal);
92
93 /** Emitted when updated software packages in bundle <b>bi</b> are
94 * are available. <b>packages</b> contains a collection of PackageInfo objects
95 * describing the updates available for installation.
96 */
98
99 /** Emitted after all available updated packages have been successfully
100 * installed.
101 */
102 void updatesInstalled(int nPackagesInstalled);
103
104 /** Emitted when there is an error installing one or more updated software
105 * packages. <b>errmsg</b> might even contain a useful description of the
106 * error encountered (but don't bet the farm on it).
107 */
108 void installUpdatesFailed(QString errmsg);
109
110public slots:
111 /** Cancels the currently running software update operation immediately. */
112 void cancel();
113
114protected slots:
115 /** Called when there is data to be read from the update process's stdout.
116 * Reads and parses all available data.
117 */
118 void readStandardOutput();
119
120 /** Called when there is data to be read from the update process's stderr.
121 * Reads and parses all available data.
122 */
123 void readStandardError();
124
125 /** Called when the underlying QProcess encounters an error.
126 */
127 void onError(QProcess::ProcessError error);
128
129 /** Called when the auto-update process has terminated.
130 */
131 void onFinished(int exitCode, QProcess::ExitStatus exitStatus);
132
133protected:
138 };
139
140 /** Converts a BundleInfo enum value to its proper Thandy-recognized URL
141 * for the current OS and architecture. */
142 QString bundleInfoToString(BundleInfo bundleInfo);
143
144 /** Returns a PackageInfo object containing information about the updated
145 * package specified by the /pkginfo/ URL in <b>package</b>.
146 */
147 static PackageInfo packageInfo(const QString &package);
148
149 /** Returns a PackageInfo object populated with information extracted
150 * from a Thandy-formatted XML document given by <b>xml</b>.
151 */
152 static PackageInfo packageInfoFromXml(const QByteArray &xml);
153
154private:
155 /** Enum value of the current auto-update operation. */
157
158 /** Enum value of the last bundle for which we performed some action
159 * (e.g., check for updates, install an update, etc. */
161
162 /** List of packages that have available updates. */
164
165 /** Currently configured SOCKS port. */
166 quint16 _socksPort;
167};
168
169#endif
170
QList< PackageInfo > PackageList
Definition: PackageInfo.h:93
BundleInfo _currentBundle
void updatesAvailable(UpdateProcess::BundleInfo bi, PackageList packages)
static PackageInfo packageInfoFromXml(const QByteArray &xml)
UpdateProcess(QObject *parent=0)
quint16 _socksPort
static int checkForUpdatesInterval()
void checkForUpdates(BundleInfo bi)
UpdateCommand _currentCommand
void installUpdatesFailed(QString errmsg)
void setSocksPort(quint16 port)
static QString updateExecutable()
void onFinished(int exitCode, QProcess::ExitStatus exitStatus)
void installUpdates(BundleInfo bi)
static PackageInfo packageInfo(const QString &package)
void onError(QProcess::ProcessError error)
void readStandardError()
QString bundleInfoToString(BundleInfo bundleInfo)
void readStandardOutput()
static QString updateRepositoryDir()
void updatesInstalled(int nPackagesInstalled)
static QDateTime nextCheckForUpdates(const QDateTime &lastCheckedAt)
bool isRunning() const
void checkForUpdatesFailed(QString errmsg)
void downloadProgress(QString url, int bytesReceived, int bytesTotal)
PackageList _packageList
static bool shouldCheckForUpdates(const QDateTime &lastCheckedAt)
DebugMessage error(const QString &fmt)
Definition: tcglobal.cpp:40