File indexing completed on 2024-04-21 04:57:20

0001 /***************************************************************************
0002  *   Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net>                     *
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or modify  *
0005  *   it under the terms of the GNU General Public License as published by  *
0006  *   the Free Software Foundation; either version 2 of the License, or     *
0007  *   (at your option) any later version.                                   *
0008  *                                                                         *
0009  *   This program is distributed in the hope that it will be useful,       *
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0012  *   GNU General Public License for more details.                          *
0013  *                                                                         *
0014  *   You should have received a copy of the GNU General Public License     *
0015  *   along with this program; if not, write to the                         *
0016  *   Free Software Foundation, Inc.,                                       *
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
0018  ***************************************************************************/
0019 
0020 #ifndef METALINKCREATOR_H
0021 #define METALINKCREATOR_H
0022 
0023 #include <KAssistantDialog>
0024 
0025 #include "filehandler.h"
0026 #include "metalinker.h"
0027 
0028 #include "ui_files.h"
0029 #include "ui_introduction.h"
0030 
0031 namespace KGetMetalink
0032 {
0033 class Metalink;
0034 }
0035 
0036 class GeneralWidget;
0037 class LanguageModel;
0038 class QDragEnterEvent;
0039 class QSortFilterProxyModel;
0040 class QStandardItemModel;
0041 
0042 class FileWidget : public QWidget
0043 {
0044     Q_OBJECT
0045 
0046 public:
0047     FileWidget(QWidget *parent = nullptr);
0048 
0049 Q_SIGNALS:
0050     void urlsDropped(const QList<QUrl> &files);
0051 
0052 protected:
0053     void dragEnterEvent(QDragEnterEvent *event) override;
0054     void dropEvent(QDropEvent *event) override;
0055 };
0056 
0057 class MetalinkCreator : public KAssistantDialog
0058 {
0059     Q_OBJECT
0060 
0061 public:
0062     MetalinkCreator(QWidget *parent = nullptr);
0063     ~MetalinkCreator() override;
0064 
0065 public Q_SLOTS:
0066     /**
0067      * Adds m_tempFile to metalink and clears it for future reuse, also adds the
0068      * filename to the filemodel
0069      */
0070     void slotAddFile();
0071 
0072     void slotAddFile(const KGetMetalink::File &file);
0073 
0074     /**
0075      * This slot is used to update the filename in the filemodel if needed
0076      */
0077     void slotFileEdited(const QString &oldFileName, const QString &newFileName);
0078 
0079     /**
0080      * Handles the dropped files, calls dialogs if needed etc
0081      * @param types the types for which checksums should be calculated
0082      * @param createPartial whether partial checksums should be created or not
0083      */
0084     void slotHandleDropped(const QStringList &types, bool createPartial);
0085 
0086 private Q_SLOTS:
0087     /**
0088      * Creates the parts that take longer
0089      */
0090     void slotDelayedCreation();
0091 
0092     /**
0093      * Deactivates the Next/Finish-Button when the metalink is not valid i.e. data is missing
0094      */
0095     void slotUpdateAssistantButtons(KPageWidgetItem *to = nullptr, KPageWidgetItem *from = nullptr);
0096 
0097     void slotUpdateIntroductionNextButton();
0098 
0099     void slotUpdateFilesButtons();
0100 
0101     /**
0102      * Removes the selected files
0103      */
0104     void slotRemoveFile();
0105 
0106     /**
0107      * Shows the properties of a selected files, the properties can be edited
0108      */
0109     void slotFileProperties();
0110 
0111     /**
0112      * Shows a dialog where local files can be selected
0113      */
0114     void slotAddLocalFilesClicked();
0115 
0116     /**
0117      * Shows an empty file properties dialog to add a file
0118      */
0119     void slotAddClicked();
0120 
0121     /**
0122      * Saves a metalink to the destination specified in the gui, calls the other save-methods
0123      */
0124     void slotSave();
0125 
0126     void slotThreadFinished(); // TODO description
0127 
0128     void slotOpenDragDlg();
0129 
0130 private:
0131     /**
0132      * Opens the dialog to enter data for a file
0133      * @param file the file that should be modified
0134      * @param edit whether an existing file is being edited or a new one being added
0135      */
0136     void fileDlg(KGetMetalink::File *file, bool edit = false);
0137 
0138     /**
0139      * Creates the GUI parts and the needed models, calls the other create-methods
0140      */
0141     void create();
0142 
0143     /**
0144      * Loads a metalink of the destination specified in the gui, calls the other load-methods
0145      */
0146     void load();
0147 
0148     void createIntroduction();
0149 
0150     void createGeneral();
0151     void loadGeneral();
0152     void saveGeneral();
0153 
0154     void createFiles();
0155     void loadFiles();
0156 
0157 private:
0158     FileHandlerThread m_thread;
0159     DirectoryHandler *m_handler;
0160     KGetMetalink::Metalink metalink;
0161     int m_needUrlCount;
0162 
0163     KGetMetalink::File m_tempFile;
0164     KGetMetalink::Resources m_tempResources;
0165     KGetMetalink::CommonData m_tempCommonData;
0166     bool m_createPartial;
0167 
0168     QSortFilterProxyModel *m_countrySort;
0169     LanguageModel *m_languageModel;
0170     QSortFilterProxyModel *m_languageSort;
0171 
0172     Ui::Introduction uiIntroduction;
0173     KPageWidgetItem *m_introduction;
0174 
0175     GeneralWidget *m_general;
0176     KPageWidgetItem *m_generalPage;
0177 
0178     Ui::Files uiFiles;
0179     KPageWidgetItem *m_files;
0180 
0181     QStandardItemModel *m_filesModel;
0182 };
0183 
0184 #endif