aboutsummaryrefslogtreecommitdiffstats
path: root/src/calendarsync.h
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-09-24 16:43:00 +0200
committerDanilo M. <danix@danix.xyz>2026-09-24 16:43:00 +0200
commit4ded387d3bb926982ea00f40ab01ece7ffdeaf94 (patch)
tree2c760df5da32851408ef7e6291aa7c16680ef12e /src/calendarsync.h
parent55eb08f9e03cc56c4d0e26a6c88e6ecc7222e1f3 (diff)
downloadqtmaildir-4ded387d3bb926982ea00f40ab01ece7ffdeaf94.tar.gz
qtmaildir-4ded387d3bb926982ea00f40ab01ece7ffdeaf94.zip
feat: debounce the calendar sync command after writes
Diffstat (limited to 'src/calendarsync.h')
-rw-r--r--src/calendarsync.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/calendarsync.h b/src/calendarsync.h
new file mode 100644
index 0000000..c406f79
--- /dev/null
+++ b/src/calendarsync.h
@@ -0,0 +1,54 @@
+/*
+ * qtmaildir - a Qt6 mail client for notmuch-indexed Maildirs
+ * Copyright (C) 2026 Danilo M. <danix@danix.xyz>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#pragma once
+
+#include <QObject>
+#include <QProcess>
+#include <QTimer>
+
+/// Runs calendar_sync_command a short delay after the last write.
+///
+/// The calendar's counterpart to MailSync, and deliberately smaller: no lock
+/// monitoring and no status file, because the command itself takes the
+/// flock that cron shares. A write arriving while a run is in progress is not
+/// dropped: it queues exactly one more run for when this one finishes, since
+/// the running sync may have listed the vdir before the write landed.
+class CalendarSync : public QObject
+{
+ Q_OBJECT
+
+public:
+ CalendarSync(const QString &command, int delayMs, QObject *parent = nullptr);
+
+ void schedule();
+ bool isRunning() const;
+
+signals:
+ void started();
+ void finished(bool ok, const QString &output);
+
+private:
+ void run();
+
+ QString m_command;
+ QTimer m_timer;
+ QProcess m_process;
+ QByteArray m_output;
+ bool m_again = false;
+};