File indexing completed on 2024-04-21 07:27:57

0001 /*
0002     This file is part of Kiten, a KDE Japanese Reference Tool...
0003     SPDX-FileCopyrightText: 2011 Daniel E. Moctezuma <democtezuma@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef DICTIONARYUPDATEMANAGER_H
0009 #define DICTIONARYUPDATEMANAGER_H
0010 
0011 #include <QDate>
0012 #include <QFile>
0013 #include <QStringList>
0014 
0015 class QAction;
0016 class KJob;
0017 class Kiten;
0018 class KitenConfigSkeleton;
0019 
0020 /**
0021  * This class handles all the update feature for the
0022  * EDICT and KANJIDIC dictionaries.
0023  *
0024  * @author Daniel E. Moctezuma <democtezuma@gmail.com>
0025  */
0026 class DictionaryUpdateManager : public QObject
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031     /**
0032      * Constructor.
0033      *
0034      * @param parent pointer to the Kiten instance. This helps us to add
0035      *               QAction actions to the program.
0036      */
0037     explicit DictionaryUpdateManager(Kiten *parent);
0038 
0039 Q_SIGNALS:
0040     /**
0041      * Emitted when all the updates for EDICT and KANJIDIC finished.
0042      */
0043     void updateFinished();
0044 
0045 private Q_SLOTS:
0046     /**
0047      * Downloads an information file containing:
0048      *   Name of dictionary
0049      *   Copyright information
0050      *   Latest creation date
0051      *   Number of entries in the dictionary
0052      */
0053     void checkForUpdates();
0054     /**
0055      * Compare the downloaded information file with our
0056      * dictionaries and check whether or not we need to
0057      * update, if so, this function triggers their download.
0058      *
0059      * @param job the job that downloaded the information file.
0060      *            This slot should be connected to the result() signal from KJob.
0061      */
0062     void checkInfoFile(KJob *job);
0063     /**
0064      * Install the downloaded dictionary.
0065      *
0066      * @param job the job that downloaded a dictionary file.
0067      *            This slot should be connected to the result() signal from KJob.
0068      */
0069     void installDictionary(KJob *job);
0070     /**
0071      * Show the update results as a KMessageBox.
0072      */
0073     void showUpdateResults();
0074 
0075 private:
0076     /**
0077      * Check whether or not the update finished, if so,
0078      * Q_EMIT an updateFinished signal.
0079      */
0080     void checkIfUpdateFinished();
0081     /**
0082      * Return the creation date of a file.
0083      * Files could be:
0084      *   Information file
0085      *   EDICT
0086      *   KANJIDIC
0087      *
0088      * @param file file from which you want to get the creation date
0089      * @return creation date of the given file
0090      */
0091     QDate getFileDate(QFile &file);
0092     /**
0093      * Download a dictionary.
0094      * Could be:
0095      *   EDICT
0096      *   KANJIDIC
0097      *
0098      * @param url url to the dictionary you want to download
0099      */
0100     void downloadDictionary(const QString &url);
0101 
0102     /**
0103      * We need it to add a QAction action to the main toolbar.
0104      */
0105     Kiten *_parent;
0106     /**
0107      * Config file that we need to know the path to
0108      * the installed dictionaries.
0109      */
0110     KitenConfigSkeleton *_config;
0111     /**
0112      * Update action.
0113      */
0114     QAction *_actionUpdate;
0115     /**
0116      * List of dictionaries already up to date.
0117      */
0118     QStringList _succeeded;
0119     /**
0120      * List of dictionaries that failed to be updated.
0121      */
0122     QStringList _failed;
0123     /**
0124      * Counter to know how many dictionaries we are trying to
0125      * install (to be used inside the installDictionary private slot).
0126      */
0127     int _counter;
0128 };
0129 
0130 #endif