|
27 | 27 | #include <QMouseEvent> |
28 | 28 | #include <QPainter> |
29 | 29 | #include <QPointer> |
30 | | -#include <QProgressDialog> |
31 | 30 | #include <QPushButton> |
32 | 31 | #include <QResizeEvent> |
33 | 32 | #include <QStringList> |
34 | 33 | #include <QStyleOption> |
35 | 34 | #include <QTimer> |
36 | 35 | #include <QVBoxLayout> |
37 | 36 |
|
| 37 | +#include "QTMTemplateOpener.hpp" |
38 | 38 | #include "qt_dpi_utils.hpp" |
39 | 39 | #include "qt_floating_toast.hpp" |
40 | | -#include "qt_template_utils.hpp" |
41 | 40 | #include "qt_utilities.hpp" |
42 | 41 | #include "s7_tm.hpp" |
43 | 42 | #include "sys_utils.hpp" |
@@ -761,83 +760,15 @@ QTMHomePage::createDocumentWithStyle (const QString& styleId) { |
761 | 760 |
|
762 | 761 | for (const auto& style : styles_) { |
763 | 762 | if (style.id == styleId) { |
764 | | - createDocumentFromTemplate (style.templateId); |
| 763 | + QTMTemplateOpener opener (this); |
| 764 | + opener.openTemplate (style.templateId); |
765 | 765 | return; |
766 | 766 | } |
767 | 767 | } |
768 | 768 |
|
769 | 769 | qWarning () << "Invalid style ID:" << styleId; |
770 | 770 | } |
771 | 771 |
|
772 | | -void |
773 | | -QTMHomePage::createDocumentFromTemplate (const QString& templateId) { |
774 | | - TemplateManager* mgr= TemplateManager::instance (); |
775 | | - if (!mgr) return; |
776 | | - |
777 | | - if (mgr->isTemplateAvailableLocally (templateId)) { |
778 | | - auto meta= mgr->templateById (templateId); |
779 | | - if (!meta) { |
780 | | - QtFloatingToast::showToast (this, |
781 | | - qt_translate ("Template metadata not found"), |
782 | | - 3000, QtFloatingToast::Error); |
783 | | - return; |
784 | | - } |
785 | | - QString localPath= mgr->localTemplatePath (templateId); |
786 | | - if (localPath.isEmpty ()) { |
787 | | - QtFloatingToast::showToast ( |
788 | | - this, qt_translate ("Local template file is missing"), 3000, |
789 | | - QtFloatingToast::Error); |
790 | | - return; |
791 | | - } |
792 | | - qt_copy_template_and_load (this, localPath, meta->name); |
793 | | - return; |
794 | | - } |
795 | | - |
796 | | - QProgressDialog dialog (qt_translate ("Downloading template..."), |
797 | | - qt_translate ("Cancel"), 0, 100, this); |
798 | | - dialog.setWindowModality (Qt::WindowModal); |
799 | | - dialog.setAutoClose (true); |
800 | | - |
801 | | - bool cancelledByUser= false; |
802 | | - connect (&dialog, &QProgressDialog::canceled, [&] () { |
803 | | - cancelledByUser= true; |
804 | | - mgr->cancelDownload (templateId); |
805 | | - }); |
806 | | - |
807 | | - connect (mgr, &TemplateManager::downloadProgress, &dialog, |
808 | | - [&dialog] (const QString&, qint64 received, qint64 total) { |
809 | | - if (total <= 0) return; |
810 | | - dialog.setMaximum (static_cast<int> (total)); |
811 | | - dialog.setValue (static_cast<int> (received)); |
812 | | - }); |
813 | | - |
814 | | - dialog.show (); |
815 | | - |
816 | | - QString errorMsg; |
817 | | - QString localPath= mgr->downloadTemplateSync (templateId, 30000, &errorMsg); |
818 | | - |
819 | | - dialog.hide (); |
820 | | - |
821 | | - if (localPath.isEmpty ()) { |
822 | | - if (!cancelledByUser) { |
823 | | - QtFloatingToast::showToast ( |
824 | | - this, |
825 | | - errorMsg.isEmpty () ? qt_translate ("Download failed") : errorMsg, |
826 | | - 3000, QtFloatingToast::Error); |
827 | | - } |
828 | | - return; |
829 | | - } |
830 | | - |
831 | | - auto meta= mgr->templateById (templateId); |
832 | | - if (!meta) { |
833 | | - QtFloatingToast::showToast (this, |
834 | | - qt_translate ("Template metadata not found"), |
835 | | - 3000, QtFloatingToast::Error); |
836 | | - return; |
837 | | - } |
838 | | - qt_copy_template_and_load (this, localPath, meta->name); |
839 | | -} |
840 | | - |
841 | 772 | void |
842 | 773 | QTMHomePage::refreshTemplateThumbnails () { |
843 | 774 | TemplateManager* mgr= TemplateManager::instance (); |
|
0 commit comments