[office/skrooge] /: UI: Chose whether to convert existing schedules on template mode change

Nikita Krupenko null at kde.org
Sat Dec 9 21:32:07 GMT 2023


Git commit 2fa4d5565411c33f8cd74c343e6bafbb3a2b990e by Nikita Krupenko.
Committed on 09/12/2023 at 13:54.
Pushed by smankowski into branch 'master'.

UI: Chose whether to convert existing schedules on template mode change

One need to explicitly select this option to perform the conversion.

M  +8    -0    doc/index.docbook
A  +-    --    doc/settings_scheduled_convert.png
M  +4    -0    plugins/skrooge/skrooge_scheduled/skgscheduled_settings.kcfg
M  +1    -1    plugins/skrooge/skrooge_scheduled/skgscheduled_settings.kcfgc
M  +24   -1    plugins/skrooge/skrooge_scheduled/skgscheduledplugin.cpp
M  +2    -0    plugins/skrooge/skrooge_scheduled/skgscheduledplugin.h
M  +9    -1    plugins/skrooge/skrooge_scheduled/skgscheduledpluginwidget_pref.ui

https://invent.kde.org/office/skrooge/-/commit/2fa4d5565411c33f8cd74c343e6bafbb3a2b990e

diff --git a/doc/index.docbook b/doc/index.docbook
index 3bcb46b99..20426fa75 100644
--- a/doc/index.docbook
+++ b/doc/index.docbook
@@ -2618,6 +2618,14 @@ file is opened. It is also recommended to create a different account (⪚ "ETF"
             </mediaobject>
         </screenshot>
         <para>Here you will find options for editing scheduled operations.</para>
+        <para>If you toggle the create template option, and additional option will appear that will allow you to convert all existing scheduled operations.</para>
+        <screenshot>
+            <mediaobject>
+            <imageobject>
+                <imagedata fileref="settings_scheduled_convert.png" format="PNG"/>
+            </imageobject>
+            </mediaobject>
+        </screenshot>
         </sect1>
 
         <sect1 id="settings_search">
diff --git a/doc/settings_scheduled_convert.png b/doc/settings_scheduled_convert.png
new file mode 100644
index 000000000..064189c54
Binary files /dev/null and b/doc/settings_scheduled_convert.png differ
diff --git a/plugins/skrooge/skrooge_scheduled/skgscheduled_settings.kcfg b/plugins/skrooge/skrooge_scheduled/skgscheduled_settings.kcfg
index 0c280555f..23fe7f1f4 100644
--- a/plugins/skrooge/skrooge_scheduled/skgscheduled_settings.kcfg
+++ b/plugins/skrooge/skrooge_scheduled/skgscheduled_settings.kcfg
@@ -13,6 +13,10 @@
 	<label>Create a template when an operation is scheduled</label>
 	<default>true</default>
     </entry>
+    <entry name="convert_to_from_template" type="Bool">
+        <label>Convert all existing scheduled oprations to/from template</label>
+        <default>false</default>
+    </entry>
     <entry name="remind_me" type="Bool">
 	<label>Remind Me</label>
 	<default>true</default>
diff --git a/plugins/skrooge/skrooge_scheduled/skgscheduled_settings.kcfgc b/plugins/skrooge/skrooge_scheduled/skgscheduled_settings.kcfgc
index c75093da8..2bf17067d 100644
--- a/plugins/skrooge/skrooge_scheduled/skgscheduled_settings.kcfgc
+++ b/plugins/skrooge/skrooge_scheduled/skgscheduled_settings.kcfgc
@@ -2,5 +2,5 @@
 File=skgscheduled_settings.kcfg
 ClassName=skgscheduled_settings
 Singleton=true
-Mutators=col_background,col_foreground
+Mutators=convert_to_from_template
 # will create the necessary code for setting those variables
diff --git a/plugins/skrooge/skrooge_scheduled/skgscheduledplugin.cpp b/plugins/skrooge/skrooge_scheduled/skgscheduledplugin.cpp
index 8d7e853ad..6efaf509e 100644
--- a/plugins/skrooge/skrooge_scheduled/skgscheduledplugin.cpp
+++ b/plugins/skrooge/skrooge_scheduled/skgscheduledplugin.cpp
@@ -251,6 +251,20 @@ QWidget* SKGScheduledPlugin::getPreferenceWidget()
     auto w = new QWidget();
     ui.setupUi(w);
 
+    ui.kcfg_convert_to_from_template->hide();
+    clearConvertToFromTemplateSetting();
+
+    connect(skgscheduled_settings::self(), &skgscheduled_settings::configChanged,
+        ui.kcfg_convert_to_from_template, [this] () {
+            ui.kcfg_convert_to_from_template->setChecked(false);
+            ui.kcfg_convert_to_from_template->hide();
+        });
+    connect(ui.kcfg_create_template, &QCheckBox::toggled,
+        this, [this] (bool isChecked) {
+            ui.kcfg_convert_to_from_template->setChecked(false);
+            const bool isChanged = (isChecked != skgscheduled_settings::create_template());
+            ui.kcfg_convert_to_from_template->setVisible(isChanged);
+        });
     connect(ui.kcfg_remind_me, &QCheckBox::toggled, ui.kcfg_remind_me_days, &QSpinBox::setEnabled);
     connect(ui.kcfg_remind_me, &QCheckBox::toggled, ui.label_3, &QSpinBox::setEnabled);
     connect(ui.kcfg_nb_times, &QCheckBox::toggled, ui.kcfg_nb_times_val, &QSpinBox::setEnabled);
@@ -301,7 +315,7 @@ SKGError SKGScheduledPlugin::savePreferences() const
     SKGError err;
     if (m_currentBankDocument != nullptr) {
         // Read Setting
-        {
+        if (skgscheduled_settings::convert_to_from_template()) {
             const auto newTemplateMode = skgscheduled_settings::create_template();
             SKGObjectBase::SKGListSKGObjectBase recurrents;
             err = m_currentBankDocument->getObjects(QStringLiteral("v_recurrentoperation"), QStringLiteral("(select count(1) from operation where operation.id=rd_operation_id and t_template='%1')=1").arg(newTemplateMode ? "N" : "Y"), recurrents);
@@ -316,11 +330,20 @@ SKGError SKGScheduledPlugin::savePreferences() const
                 }
                 IFOK(err) m_currentBankDocument->sendMessage(i18nc("An information message",  "All scheduled operations have been converted in template"));
             }
+
+            clearConvertToFromTemplateSetting();
         }
     }
     return err;
 }
 
+void SKGScheduledPlugin::clearConvertToFromTemplateSetting() const
+{
+    // This setting should be enabled only manually and we reset it after conversion is done
+    skgscheduled_settings::setConvert_to_from_template(false);
+    skgscheduled_settings::self()->save();
+}
+
 SKGError SKGScheduledPlugin::scheduleOperation(const SKGOperationObject& iOperation, SKGRecurrentOperationObject& oRecurrent) const
 {
     SKGError err;
diff --git a/plugins/skrooge/skrooge_scheduled/skgscheduledplugin.h b/plugins/skrooge/skrooge_scheduled/skgscheduledplugin.h
index fbc097f2e..236d7b967 100644
--- a/plugins/skrooge/skrooge_scheduled/skgscheduledplugin.h
+++ b/plugins/skrooge/skrooge_scheduled/skgscheduledplugin.h
@@ -155,6 +155,8 @@ private Q_SLOTS:
 private:
     Q_DISABLE_COPY(SKGScheduledPlugin)
 
+    void clearConvertToFromTemplateSetting() const;
+
     SKGError scheduleOperation(const SKGOperationObject& iOperation, SKGRecurrentOperationObject& oRecurrent) const;
 
     SKGDocumentBank* m_currentBankDocument;
diff --git a/plugins/skrooge/skrooge_scheduled/skgscheduledpluginwidget_pref.ui b/plugins/skrooge/skrooge_scheduled/skgscheduledpluginwidget_pref.ui
index fc8648e9b..3945aeb3d 100644
--- a/plugins/skrooge/skrooge_scheduled/skgscheduledpluginwidget_pref.ui
+++ b/plugins/skrooge/skrooge_scheduled/skgscheduledpluginwidget_pref.ui
@@ -12,7 +12,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
     <x>0</x>
     <y>0</y>
     <width>555</width>
-    <height>324</height>
+    <height>330</height>
    </rect>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
@@ -42,6 +42,13 @@ SPDX-License-Identifier: GPL-3.0-or-later
      </property>
     </widget>
    </item>
+   <item>
+    <widget class="QCheckBox" name="kcfg_convert_to_from_template">
+     <property name="text">
+      <string>Convert all existing scheduled oprations to/from template</string>
+     </property>
+    </widget>
+   </item>
    <item>
     <widget class="QGroupBox" name="fontBox">
      <property name="title">
@@ -279,6 +286,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
  <tabstops>
   <tabstop>kcfg_check_on_open</tabstop>
   <tabstop>kcfg_create_template</tabstop>
+  <tabstop>kcfg_convert_to_from_template</tabstop>
   <tabstop>kcfg_fontDisabledColor</tabstop>
   <tabstop>kcfg_once_every</tabstop>
   <tabstop>kcfg_once_every_unit</tabstop>



More information about the kde-doc-english mailing list