File indexing completed on 2024-04-21 05:30:55

0001 /*
0002     SPDX-FileCopyrightText: 2021 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef EXPORTTEMPLATEHANDLER_H
0007 #define EXPORTTEMPLATEHANDLER_H
0008 
0009 // local
0010 #include "../generic/generichandler.h"
0011 #include "../../data/appletdata.h"
0012 #include "../../data/layoutdata.h"
0013 #include "../../data/viewdata.h"
0014 
0015 // Qt
0016 #include <QButtonGroup>
0017 #include <QSortFilterProxyModel>
0018 
0019 namespace Ui {
0020 class ExportTemplateDialog;
0021 }
0022 
0023 namespace Latte{
0024 class View;
0025 namespace Settings{
0026 namespace Dialog{
0027 class ExportTemplateDialog;
0028 }
0029 }
0030 }
0031 
0032 namespace Latte{
0033 namespace Settings{
0034 namespace Model {
0035 class Applets;
0036 }
0037 }
0038 }
0039 
0040 
0041 namespace Latte {
0042 namespace Settings {
0043 namespace Handler {
0044 
0045 //! Handlers are objects to handle the UI elements that semantically associate with specific
0046 //! ui::tabs or different windows. They are responsible also to handle the user interaction
0047 //! between controllers and views
0048 
0049 class ExportTemplateHandler : public Generic
0050 {
0051     Q_OBJECT
0052 public:
0053     ExportTemplateHandler(Dialog::ExportTemplateDialog *dialog);
0054     ExportTemplateHandler(Dialog::ExportTemplateDialog *dialog, const Data::Layout &layout);
0055     ExportTemplateHandler(Dialog::ExportTemplateDialog *dialog, const Data::View &view);
0056     ExportTemplateHandler(Dialog::ExportTemplateDialog *dialog, Latte::View *view);
0057     ~ExportTemplateHandler();
0058 
0059     bool hasChangedData() const override;
0060     bool inDefaultValues() const override;
0061 
0062     Latte::Data::AppletsTable currentData() const;
0063 
0064 public slots:
0065     void reset() override;
0066     void resetDefaults() override;
0067     void save() override;
0068 
0069 signals:
0070     void filepathChanged();
0071     void exportSucceeded();
0072 
0073 private:
0074     void init();
0075     void initDefaults();
0076 
0077     void loadApplets(const QString &file);
0078     void loadViewApplets(Latte::View *view);
0079 
0080     void setFilepath(const QString &filepath);
0081 
0082     bool overwriteConfirmation(const QString &fileName);
0083 
0084 private slots:
0085     void onExport();
0086     void onFilepathChanged();
0087     void onSelectAll();
0088     void onDeselectAll();
0089 
0090     void chooseFileDialog();
0091 
0092 private:
0093     QString c_filepath;
0094     QString o_filepath;
0095 
0096     QString  m_originFilePath;
0097 
0098     Dialog::ExportTemplateDialog *m_dialog{nullptr};
0099     Ui::ExportTemplateDialog *m_ui{nullptr};
0100 
0101     //! current data
0102     Model::Applets *m_appletsModel{nullptr};
0103     QSortFilterProxyModel *m_appletsProxyModel{nullptr};
0104 };
0105 
0106 }
0107 }
0108 }
0109 
0110 #endif