Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/plugins/icalendar/export/icalendarexporter.cpp
- This file was moved from kmymoney/plugins/icalendarexport/icalendarexport.cpp.
Show All 12 Lines | |||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
15 | * GNU General Public License for more details. * | 15 | * GNU General Public License for more details. * | ||
16 | * * | 16 | * * | ||
17 | * You should have received a copy of the GNU General Public License * | 17 | * You should have received a copy of the GNU General Public License * | ||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/> * | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/> * | ||
19 | ***************************************************************************/ | 19 | ***************************************************************************/ | ||
20 | 20 | | |||
21 | #include "icalendarexport.h" | 21 | #include "icalendarexporter.h" | ||
22 | 22 | | |||
23 | #include <QFileDialog> | 23 | #include <QFileDialog> | ||
24 | #include <QUrl> | 24 | #include <QUrl> | ||
25 | #include <QAction> | 25 | #include <QAction> | ||
26 | 26 | | |||
27 | // KDE includes | 27 | // KDE includes | ||
28 | #include <KPluginFactory> | 28 | #include <KPluginFactory> | ||
29 | #include <KPluginInfo> | 29 | #include <KPluginInfo> | ||
30 | #include <KActionCollection> | 30 | #include <KActionCollection> | ||
31 | #include <KSharedConfig> | 31 | #include <KSharedConfig> | ||
32 | #include <KLocalizedString> | 32 | #include <KLocalizedString> | ||
33 | 33 | | |||
34 | // KMyMoney includes | 34 | // KMyMoney includes | ||
35 | #include "mymoneyfile.h" | 35 | #include "mymoneyfile.h" | ||
36 | #include "pluginloader.h" | 36 | #include "pluginloader.h" | ||
37 | 37 | | |||
38 | #include "schedulestoicalendar.h" | 38 | #include "schedulestoicalendar.h" | ||
39 | #include "pluginsettings.h" | 39 | #include "pluginsettings.h" | ||
40 | 40 | | |||
41 | struct KMMiCalendarExportPlugin::Private { | 41 | struct iCalendarExporter::Private { | ||
42 | QAction* m_action; | 42 | QAction* m_action; | ||
43 | QString m_profileName; | 43 | QString m_profileName; | ||
44 | QString m_iCalendarFileEntryName; | 44 | QString m_iCalendarFileEntryName; | ||
45 | KMMSchedulesToiCalendar m_exporter; | 45 | KMMSchedulesToiCalendar m_exporter; | ||
46 | }; | 46 | }; | ||
47 | 47 | | |||
48 | KMMiCalendarExportPlugin::KMMiCalendarExportPlugin() | 48 | iCalendarExporter::iCalendarExporter(QObject *parent, const QVariantList &args) : | ||
49 | : KMyMoneyPlugin::Plugin(nullptr, "iCalendar"/*must be the same as X-KDE-PluginInfo-Name*/), | 49 | KMyMoneyPlugin::Plugin(parent, "icalendarexporter"/*must be the same as X-KDE-PluginInfo-Name*/), | ||
50 | d(std::unique_ptr<Private>(new Private)) | 50 | d(std::unique_ptr<Private>(new Private)) | ||
51 | { | 51 | { | ||
52 | Q_UNUSED(args); | ||||
52 | d->m_profileName = "iCalendarPlugin"; | 53 | d->m_profileName = "iCalendarPlugin"; | ||
53 | d->m_iCalendarFileEntryName = "iCalendarFile"; | 54 | d->m_iCalendarFileEntryName = "iCalendarFile"; | ||
54 | 55 | | |||
55 | // Tell the host application to load my GUI component | 56 | // Tell the host application to load my GUI component | ||
56 | setComponentName("kmm_icalendarexport", i18n("iCalendar exporter")); | 57 | setComponentName("icalendarexporter", i18n("iCalendar exporter")); | ||
57 | setXMLFile("kmm_icalendarexport.rc"); | 58 | setXMLFile("icalendarexporter.rc"); | ||
58 | 59 | | |||
59 | // For ease announce that we have been loaded. | 60 | // For ease announce that we have been loaded. | ||
60 | qDebug("KMyMoney iCalendar plugin loaded"); | 61 | qDebug("Plugins: icalendarexporter loaded"); | ||
61 | 62 | | |||
62 | // Create the actions of this plugin | 63 | // Create the actions of this plugin | ||
63 | QString actionName = i18n("Schedules to iCalendar"); | 64 | QString actionName = i18n("Schedules to iCalendar"); | ||
64 | QString icalFilePath; | 65 | QString icalFilePath; | ||
65 | // Note the below code only exists to move existing settings to the new plugin specific config | 66 | // Note the below code only exists to move existing settings to the new plugin specific config | ||
66 | KConfigGroup config = KSharedConfig::openConfig()->group(d->m_profileName); | 67 | KConfigGroup config = KSharedConfig::openConfig()->group(d->m_profileName); | ||
67 | icalFilePath = config.readEntry(d->m_iCalendarFileEntryName, icalFilePath); | 68 | icalFilePath = config.readEntry(d->m_iCalendarFileEntryName, icalFilePath); | ||
68 | 69 | | |||
Show All 10 Lines | 78 | } else { | |||
79 | icalFilePath = PluginSettings::icalendarFile(); | 80 | icalFilePath = PluginSettings::icalendarFile(); | ||
80 | } | 81 | } | ||
81 | 82 | | |||
82 | if (!icalFilePath.isEmpty()) | 83 | if (!icalFilePath.isEmpty()) | ||
83 | actionName = i18n("Schedules to iCalendar [%1]", icalFilePath); | 84 | actionName = i18n("Schedules to iCalendar [%1]", icalFilePath); | ||
84 | 85 | | |||
85 | d->m_action = actionCollection()->addAction("file_export_icalendar"); | 86 | d->m_action = actionCollection()->addAction("file_export_icalendar"); | ||
86 | d->m_action->setText(actionName); | 87 | d->m_action->setText(actionName); | ||
87 | connect(d->m_action, &QAction::triggered, this, &KMMiCalendarExportPlugin::slotFirstExport); | 88 | connect(d->m_action, &QAction::triggered, this, &iCalendarExporter::slotFirstExport); | ||
88 | } | 89 | } | ||
89 | 90 | | |||
90 | KMMiCalendarExportPlugin::~KMMiCalendarExportPlugin() | 91 | iCalendarExporter::~iCalendarExporter() | ||
91 | { | 92 | { | ||
93 | qDebug("Plugins: icalendarexporter unloaded"); | ||||
92 | } | 94 | } | ||
93 | 95 | | |||
94 | void KMMiCalendarExportPlugin::slotFirstExport() | 96 | void iCalendarExporter::slotFirstExport() | ||
95 | { | 97 | { | ||
96 | QPointer<QFileDialog> fileDialog = new QFileDialog(d->m_action->parentWidget(), QString(), QString(), QString("%1|%2\n").arg("*.ics").arg(i18nc("ICS (Filefilter)", "iCalendar files"))); | 98 | QPointer<QFileDialog> fileDialog = new QFileDialog(d->m_action->parentWidget(), QString(), QString(), QString("%1|%2\n").arg("*.ics").arg(i18nc("ICS (Filefilter)", "iCalendar files"))); | ||
97 | 99 | | |||
98 | fileDialog->setAcceptMode(QFileDialog::AcceptSave); | 100 | fileDialog->setAcceptMode(QFileDialog::AcceptSave); | ||
99 | fileDialog->setWindowTitle(i18n("Export as")); | 101 | fileDialog->setWindowTitle(i18n("Export as")); | ||
100 | 102 | | |||
101 | if (fileDialog->exec() == QDialog::Accepted) { | 103 | if (fileDialog->exec() == QDialog::Accepted) { | ||
102 | QUrl newURL = fileDialog->selectedUrls().front(); | 104 | QUrl newURL = fileDialog->selectedUrls().front(); | ||
103 | if (newURL.isLocalFile()) { | 105 | if (newURL.isLocalFile()) { | ||
104 | PluginSettings::setIcalendarFile(newURL.toLocalFile()); | 106 | PluginSettings::setIcalendarFile(newURL.toLocalFile()); | ||
105 | PluginSettings::self()->save(); | 107 | PluginSettings::self()->save(); | ||
106 | slotExport(); | 108 | slotExport(); | ||
107 | } | 109 | } | ||
108 | } | 110 | } | ||
109 | delete fileDialog; | 111 | delete fileDialog; | ||
110 | } | 112 | } | ||
111 | 113 | | |||
112 | void KMMiCalendarExportPlugin::slotExport() | 114 | void iCalendarExporter::slotExport() | ||
113 | { | 115 | { | ||
114 | QString icalFilePath = PluginSettings::icalendarFile(); | 116 | QString icalFilePath = PluginSettings::icalendarFile(); | ||
115 | if (!icalFilePath.isEmpty()) | 117 | if (!icalFilePath.isEmpty()) | ||
116 | d->m_exporter.exportToFile(icalFilePath); | 118 | d->m_exporter.exportToFile(icalFilePath); | ||
117 | } | 119 | } | ||
118 | 120 | | |||
119 | void KMMiCalendarExportPlugin::plug() | 121 | void iCalendarExporter::plug() | ||
120 | { | 122 | { | ||
121 | connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, this, &KMMiCalendarExportPlugin::slotExport); | 123 | connect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, this, &iCalendarExporter::slotExport); | ||
122 | } | 124 | } | ||
123 | 125 | | |||
124 | void KMMiCalendarExportPlugin::unplug() | 126 | void iCalendarExporter::unplug() | ||
125 | { | 127 | { | ||
126 | disconnect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, this, &KMMiCalendarExportPlugin::slotExport); | 128 | disconnect(MyMoneyFile::instance(), &MyMoneyFile::dataChanged, this, &iCalendarExporter::slotExport); | ||
127 | } | 129 | } | ||
128 | 130 | | |||
129 | void KMMiCalendarExportPlugin::configurationChanged() | 131 | void iCalendarExporter::configurationChanged() | ||
130 | { | 132 | { | ||
131 | PluginSettings::self()->load(); | 133 | PluginSettings::self()->load(); | ||
132 | // export the schedules because the configuration has changed | 134 | // export the schedules because the configuration has changed | ||
133 | QString icalFilePath = PluginSettings::icalendarFile(); | 135 | QString icalFilePath = PluginSettings::icalendarFile(); | ||
134 | if (!icalFilePath.isEmpty()) | 136 | if (!icalFilePath.isEmpty()) | ||
135 | d->m_exporter.exportToFile(icalFilePath); | 137 | d->m_exporter.exportToFile(icalFilePath); | ||
136 | } | 138 | } | ||
137 | 139 | | |||
140 | K_PLUGIN_FACTORY_WITH_JSON(iCalendarExporterFactory, "icalendarexporter.json", registerPlugin<iCalendarExporter>();) | ||||
141 | | ||||
142 | #include "icalendarexporter.moc" |