src/osd1/linux-r3-main-app/trunk/neuros-qt4-libs/neux/tools/nfontupdater.h

Go to the documentation of this file.
00001 #ifndef NFONTUPDATER_H
00002 #define NFONTUPDATER_H
00003 /*
00004  *  Copyright(C) 2007 Neuros Technology International LLC. 
00005  *               <www.neurostechnology.com>
00006  *
00007  *
00008  *  This program is free software; you can redistribute it and/or modify
00009  *  it under the terms of the GNU General Public License as published by
00010  *  the Free Software Foundation, version 2 of the License.
00011  *  
00012  *
00013  *  This program is distributed in the hope that, in addition to its 
00014  *  original purpose to support Neuros hardware, it will be useful 
00015  *  otherwise, but WITHOUT ANY WARRANTY; without even the implied 
00016  *  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00017  *  See the GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with this program; if not, write to the Free Software
00021  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00022  *
00023  ****************************************************************************
00024  *
00025  * NFontUpdater header
00026  * 
00027  * 
00028  * REVISION:
00029  * 
00030  * 1) Initial creation. ----------------------------------- 2008-04-28 WX
00031  *
00032  */
00033 
00034 #include <QtGlobal>
00035 #include <QObject>
00036 #include <QString>
00037 #include <QStringList>
00038 #include <QUrl>
00039 #include <QVector>
00040 #include <QFile>
00041 #include <QHttp>
00042 #include <QFontDatabase>
00043 
00044 class NFontUpdater : public QObject
00045 {
00046     Q_OBJECT
00047     Q_ENUMS(Source);
00048     Q_ENUMS(Step);
00049     Q_ENUMS(Error);
00050 
00051 public:
00052     enum Source
00053     {
00054         FromNone = 0, FromServer, FromLocal, 
00055     };
00056 
00057     enum Step
00058     {
00059         Initialize = 0, 
00060         CleanupDownloadDirectory, 
00061         CheckNextPackageToDownload,
00062         DownloadCurrentPackage, 
00063         CheckAllRequiredPackagesAvailable,
00064         RemoveFontSymlinks,
00065         RemoveFontFiles, 
00066         CheckNextPackageToUnpack,
00067         UnpackCurrentPackage, 
00068         RemoveCurrentPackage,
00069         MakeFontSymlinks, 
00070         UpdateApplicationFont,
00071         Finish
00072     };
00073 
00074     enum Error
00075     {
00076         NoError = 0, 
00077         InvalidUrl, 
00078         PackageNoFoundOnLocal, 
00079         PackageNoFoundOnServer, 
00080         LocalStorageNonexistent, 
00081         LocalStorageUnReadable,
00082         LocalStorageUnWritable, 
00083         FontFilesNoFoundOnLocal,
00084         CleanDownloadDirectoryFailed, 
00085         RemoveFontLinksFailed,
00086         RemoveFontFilesFailed, 
00087         UnpackFailed,
00088         MakeFontLinksFailed, 
00089         UpdateApplicationFontFailed,
00090         DownloadFailed, 
00091     };
00092 
00093     explicit NFontUpdater(QObject *parent = 0);
00094     ~NFontUpdater( );
00095 
00096     static bool needExtendedFont(const QString &font);
00097 
00098     void setSource(Source source) { fontSource = source; }
00099     void setFontFrom(const QString &from) { fromFont = from; }
00100     void setFontTo(const QString &to) { toFont = to; }
00101 
00102     Source source( ) const { return fontSource; }
00103     QString from( ) const { return fromFont; }
00104     QString to( ) const { return toFont; }
00105 
00106      //FromServer: it is the directory to storage downloaded package, AND it will be cleanuped.
00107      //FromLocal: it is the storage directory where should contain font packages.
00108     void setLocalStorage(const QString &path) { localStorageDir = path; }
00109 
00110     QString currentPackage( ) const { return -1 == currentPackageIndex ? "" : fontPackageList[currentPackageIndex]; }
00111 
00112     Error error( ) const { return updateError; }
00113     QString errorString( ) { return updateErrorString; }
00114 
00115     Step currentStep( ) const { return stepSequence[currentStepIndex]; }
00116     Step nextStep( ) const { return stepSequence[nextStepIndex]; }
00117     void initUpdater( );
00118     void cleanup( );
00119     void doNextStep( );
00120 
00121     bool init( );
00122     bool cleanupDownloadDirectory( );
00123     bool startDownloadCurrentPackage( );
00124     int checkNextPackageToDownload( ); // -1: error, 0: no more package, 1: there is a next package need to process
00125     int checkNextPackageToUnpack( );
00126     bool checkAllRequiredPackagesAvailable( );
00127     bool removeFontSymlinks( );
00128     bool removeFontFiles( );
00129     bool unpackCurrentPackage( );
00130     bool removeCurrentPackage( );
00131     bool makeFontSymlinks( );
00132     bool updateApplicationFont( );
00133     bool finish( );
00134 
00135 Q_SIGNALS:
00136     void stepFinished(bool error);
00137     void httpDone(bool error);
00138 
00139 private Q_SLOTS:
00140     void onHttpResponseHeaderReceived(const QHttpResponseHeader &resp);
00141     void onHttpRequestFinished(int id, bool error);
00142 
00143 private:
00144     void setError(Error error) { updateError = error; }
00145     void setErrorString(const QString &text) { updateErrorString = text; }
00146     QVector<Step> getStepSequence(Source source, const QString &from, const QString &to) const;
00147     QStringList getDefaultPackages(const QString &font) const;
00148     QString getPackageName(int index) const;
00149     QString getDefaultServerStorageDir(const QString &font) const;
00150     QString getDefaultLocalStorageDir(Source source) const;
00151     QString convertToPath(const QStringList &list) const;
00152 
00153 private:
00154     Source fontSource;
00155     Error updateError;
00156     QString updateErrorString;
00157     QString fromFont;
00158     QString toFont;
00159 
00160     QVector<Step> stepSequence;
00161     int currentStepIndex;
00162     int nextStepIndex;
00163 
00164     int currentHttpGetId;
00165     bool currentHttpGetFinished;
00166     QFile *currentHttpGetFile;
00167     QHttp *currentHttp;
00168     QUrl currentPackageUrl;
00169     QString serverStorageDir;
00170     QString localStorageDir;
00171     QStringList fontPackageList;
00172     int currentPackageIndex;
00173 };
00174 
00175 #endif // NFONTUPDATER_H
00176 

Generated on Fri Oct 10 02:31:12 2008 for Neuros OSD1.0 linux-r3-main-app/neuros-qt4-libs by  1.5.1