From c10fa090bc59da5c2ba7b7c13868bb86c36bc729 Mon Sep 17 00:00:00 2001 From: James Hogan Date: Fri, 7 Nov 2008 01:08:17 +0000 Subject: [PATCH] KPresenter 1.6 backend: interval polling of document list --- unipresent/kpresenter1/UpKpr1Backend.cpp | 82 ++++++++++++++++++++++----- unipresent/kpresenter1/UpKpr1Backend.h | 23 ++++++++ unipresent/kpresenter1/UpKpr1Dcop.cpp | 6 ++ unipresent/kpresenter1/UpKpr1Dcop.h | 3 + unipresent/kpresenter1/UpKpr1Presentation.cpp | 8 +-- unipresent/kpresenter1/UpKpr1Presentation.h | 2 +- 6 files changed, 105 insertions(+), 19 deletions(-) diff --git a/unipresent/kpresenter1/UpKpr1Backend.cpp b/unipresent/kpresenter1/UpKpr1Backend.cpp index e8a8c18..051ae1d 100644 --- a/unipresent/kpresenter1/UpKpr1Backend.cpp +++ b/unipresent/kpresenter1/UpKpr1Backend.cpp @@ -31,6 +31,8 @@ #include +#include + /* * Constructors + destructor */ @@ -39,7 +41,10 @@ UpKpr1Backend::UpKpr1Backend(QObject* parent) : UpBackend(parent) , m_presentations() +, m_refreshTimer(new QTimer(this)) { + connect(m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh())); + m_refreshTimer->start(15000); activate(); } @@ -93,19 +98,7 @@ bool UpKpr1Backend::isActive() bool UpKpr1Backend::activate() { - if (m_presentations.empty()) - { - UpKpr1AppsDcop apps; - QList kprs = apps.kpresenters(); - foreach(UpKpr1KpresenterDcop kpr, kprs) - { - QList docs = kpr.documents(); - foreach (UpKpr1PresentationDcop doc, docs) - { - m_presentations << new UpKpr1Presentation(doc, this); - } - } - } + refresh(); return true; } @@ -127,3 +120,66 @@ bool UpKpr1Backend::openPresentation(const QUrl& url) return false; } +/* + * Private slots + */ + +/// Hit at intervals to refresh presentation list. +void UpKpr1Backend::refresh() +{ + QList lostPresentations = m_presentations; + + UpKpr1AppsDcop apps; + QList kprs = apps.kpresenters(); + foreach(UpKpr1KpresenterDcop kpr, kprs) + { + QList docs = kpr.documents(); + foreach (UpKpr1PresentationDcop doc, docs) + { + // Must have a view to be useful + UpKpr1ViewDcop view = doc.view(); + if (view.isValid()) + { + UpPresentation* presentation = presentationByDcop(doc.reference()); + if (0 != presentation) + { + // Already exists, remove from lost list + lostPresentations.removeOne(presentation); + } + else + { + // New, create + presentation = new UpKpr1Presentation(doc, view, this); + m_presentations << presentation; + loadedPresentation(presentation); + } + } + } + } + + // Anything left in lost list needs removing + foreach (UpPresentation* presentation, lostPresentations) + { + unloadedPresentation(presentation); + delete presentation; + m_presentations.removeOne(presentation); + } +} + +/* + * Private functions + */ + +/// Find a presentation identified by a dcop reference. +UpPresentation* UpKpr1Backend::presentationByDcop(const QStringList& dcopRef) const +{ + foreach (UpPresentation* presentation, m_presentations) + { + if (static_cast(presentation)->dcop().reference() == dcopRef) + { + return presentation; + } + } + return 0; +} + diff --git a/unipresent/kpresenter1/UpKpr1Backend.h b/unipresent/kpresenter1/UpKpr1Backend.h index e6e160b..1bb2f4b 100644 --- a/unipresent/kpresenter1/UpKpr1Backend.h +++ b/unipresent/kpresenter1/UpKpr1Backend.h @@ -28,11 +28,16 @@ #include "UpBackend.h" +class QTimer; +class QStringList; + /** KPresenter 1 presentation manager. * This is a messy backend to use the DCOP interface. */ class UpKpr1Backend : public UpBackend { + Q_OBJECT + public: /* @@ -70,15 +75,33 @@ class UpKpr1Backend : public UpBackend virtual QList presentations(); virtual bool openPresentation(const QUrl& url); + private slots: + + /* + * Private slots + */ + + /// Hit at intervals to refresh presentation list. + void refresh(); + private: /* + * Private functions + */ + + /// Find a presentation identified by a dcop reference. + UpPresentation* presentationByDcop(const QStringList& dcopRef) const; + + /* * Variables */ /// List of presentations. QList m_presentations; + /// Refresh timer. + QTimer* m_refreshTimer; }; #endif // _UpKpr1Backend_h_ diff --git a/unipresent/kpresenter1/UpKpr1Dcop.cpp b/unipresent/kpresenter1/UpKpr1Dcop.cpp index 99094ee..9820216 100644 --- a/unipresent/kpresenter1/UpKpr1Dcop.cpp +++ b/unipresent/kpresenter1/UpKpr1Dcop.cpp @@ -68,6 +68,12 @@ bool UpKpr1Dcop::isValid() const return m_valid; } +/// Get the dcop reference. +const QStringList& UpKpr1Dcop::reference() const +{ + return m_reference; +} + /* * Helper methods */ diff --git a/unipresent/kpresenter1/UpKpr1Dcop.h b/unipresent/kpresenter1/UpKpr1Dcop.h index ad377fc..e7f913b 100644 --- a/unipresent/kpresenter1/UpKpr1Dcop.h +++ b/unipresent/kpresenter1/UpKpr1Dcop.h @@ -56,6 +56,9 @@ class UpKpr1Dcop /// Find whether its valid. bool isValid() const; + /// Get the dcop reference. + const QStringList& reference() const; + /* * Helper methods */ diff --git a/unipresent/kpresenter1/UpKpr1Presentation.cpp b/unipresent/kpresenter1/UpKpr1Presentation.cpp index 0abb2fe..1056007 100644 --- a/unipresent/kpresenter1/UpKpr1Presentation.cpp +++ b/unipresent/kpresenter1/UpKpr1Presentation.cpp @@ -27,20 +27,18 @@ #include "UpKpr1Slide.h" #include "UpKpr1Backend.h" -#include - /* * Constructors + destructor */ /// Primary constructor. -UpKpr1Presentation::UpKpr1Presentation(const UpKpr1PresentationDcop& dcop, UpKpr1Backend* parent) +UpKpr1Presentation::UpKpr1Presentation(const UpKpr1PresentationDcop& dcop, const UpKpr1ViewDcop& dcopView, UpKpr1Backend* parent) : UpPresentation(parent, parent) , m_dcop(dcop) -, m_dcopView(dcop.view()) +, m_dcopView(dcopView) , m_url(dcop.url()) { - assert(m_dcopView.isValid()); + Q_ASSERT(m_dcopView.isValid()); } /// Destructor. diff --git a/unipresent/kpresenter1/UpKpr1Presentation.h b/unipresent/kpresenter1/UpKpr1Presentation.h index c6063de..a4ad066 100644 --- a/unipresent/kpresenter1/UpKpr1Presentation.h +++ b/unipresent/kpresenter1/UpKpr1Presentation.h @@ -46,7 +46,7 @@ class UpKpr1Presentation : public UpPresentation */ /// Primary constructor. - UpKpr1Presentation(const UpKpr1PresentationDcop& dcop, UpKpr1Backend* parent = 0); + UpKpr1Presentation(const UpKpr1PresentationDcop& dcop, const UpKpr1ViewDcop& dcopView, UpKpr1Backend* parent = 0); /// Destructor. virtual ~UpKpr1Presentation(); -- 2.11.4.GIT