[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [sprinter/gko/master] /: make QueryMatch hold the SessionData, and have RunnerSessionData set it
From:       Aaron J. Seigo <aseigo () kde ! org>
Date:       2014-03-06 10:20:20
Message-ID: E1WLVPY-0007ZS-T9 () scm ! kde ! org
[Download RAW message or body]

Git commit 546f76da31fa6df6e1a26b684699f5f16dee0db4 by Aaron J. Seigo.
Committed on 25/02/2014 at 16:30.
Pushed by aseigo into branch 'gko/master'.

make QueryMatch hold the SessionData, and have RunnerSessionData set it

previously QueryMatch was keeping track of its associated runner. but
matches belong sessions, really, and from a sessiondata object the
runner can be retrieved. this also allows runners to use the
sessiondata in exec()

where this may cause issues in future is in saving/restoring QueryMatch
objects and then exec'ing them. something we did iirc in Plasma Netbook's
Search and Launch. something to replace that functionality may well be
needed in future, and should probably be placed in QuerySession itself
to avoid ad-hoc hacks.

M  +1    -1    runners/activities/activities.cpp
M  +1    -1    runners/c/c.cpp
M  +2    -2    runners/calculator/calculator.cpp
M  +4    -4    runners/datetime/datetime.cpp
M  +1    -1    runners/youtube/youtube.cpp
M  +12   -34   sprinter/querymatch.cpp
M  +12   -8    sprinter/querymatch.h
M  +5    -0    sprinter/runnersessiondata.cpp

http://commits.kde.org/sprinter/546f76da31fa6df6e1a26b684699f5f16dee0db4

diff --git a/runners/activities/activities.cpp b/runners/activities/activities.cpp
index a38d5f1..f36c36a 100644
--- a/runners/activities/activities.cpp
+++ b/runners/activities/activities.cpp
@@ -200,7 +200,7 @@ void ActivityRunner::addMatch(const KActivities::Info &activity,
                               const Sprinter::QueryContext &context,
                               QVector<Sprinter::QueryMatch> &matches)
 {
-    Sprinter::QueryMatch match(this);
+    Sprinter::QueryMatch match;
     match.setData(activity.id());
     match.setType(Sprinter::QuerySession::ActivityType);
     match.setSource(Sprinter::QuerySession::FromLocalService);
diff --git a/runners/c/c.cpp b/runners/c/c.cpp
index ac3295d..55f97ad 100644
--- a/runners/c/c.cpp
+++ b/runners/c/c.cpp
@@ -32,7 +32,7 @@ void RunnerC::match(Sprinter::RunnerSessionData *sessionData, const \
Sprinter::Qu  {
     QVector<Sprinter::QueryMatch> matches;
     if (context.isDefaultMatchesRequest() || context.query() == "plasma") {
-        Sprinter::QueryMatch match(this);
+        Sprinter::QueryMatch match;
         match.setTitle("Plasma");
         match.setText("Rocks");
         match.setPrecision(Sprinter::QuerySession::ExactMatch);
diff --git a/runners/calculator/calculator.cpp b/runners/calculator/calculator.cpp
index 9ce3f49..0d5ab79 100644
--- a/runners/calculator/calculator.cpp
+++ b/runners/calculator/calculator.cpp
@@ -83,7 +83,7 @@ void CalculatorRunner::match(Sprinter::RunnerSessionData *sd,
     cmd = cmd.trimmed().remove(' ');
 
     if (cmd.toLower() == "universe" || cmd.toLower() == "life") {
-        Sprinter::QueryMatch match(this);
+        Sprinter::QueryMatch match;
         match.setPrecision(Sprinter::QuerySession::ExactMatch);
         match.setType(Sprinter::QuerySession::MathAndUnitsType);
         match.setSource(Sprinter::QuerySession::FromInternalSource);
@@ -141,7 +141,7 @@ void CalculatorRunner::match(Sprinter::RunnerSessionData *sd,
             result = "0x" + QString::number(result.toInt(), 16).toUpper();
         }
 
-        Sprinter::QueryMatch match(this);
+        Sprinter::QueryMatch match;
         match.setPrecision(Sprinter::QuerySession::ExactMatch);
         match.setType(Sprinter::QuerySession::MathAndUnitsType);
         match.setSource(Sprinter::QuerySession::FromInternalSource);
diff --git a/runners/datetime/datetime.cpp b/runners/datetime/datetime.cpp
index 9887fc3..d754a81 100644
--- a/runners/datetime/datetime.cpp
+++ b/runners/datetime/datetime.cpp
@@ -55,9 +55,9 @@ void DateTimeSessionData::performUpdate()
     Sprinter::QueryMatch update;
     foreach (const Sprinter::QueryMatch &match, matches(SynchronizedMatches)) {
         update = dtr->performMatch(match.data().toString());
-        update.setImage(dtr->image());
 
         if (update.isValid()) {
+            update.setImage(dtr->image());
             updates << update;
         }
     }
@@ -81,7 +81,7 @@ DateTimeRunner::DateTimeRunner(QObject *parent)
 
 Sprinter::QueryMatch DateTimeRunner::createMatch(const QString &title, const QString \
&userData, const QString &data)  {
-    Sprinter::QueryMatch match(this);
+    Sprinter::QueryMatch match;
     match.setTitle(title);
     match.setUserData(userData);
     match.setData(data);
@@ -164,9 +164,9 @@ void DateTimeRunner::match(Sprinter::RunnerSessionData \
*sessionData, const Sprin  {
     Sprinter::QueryMatch match = performMatch(context.query());
 
-//     qDebug() << "got" << match.text() << match.isValid();
+//     qDebug() << "got" << match.text() << (!match.data().isNull());
     QVector<Sprinter::QueryMatch> matches;
-    if (match.isValid()) {
+    if (!match.data().isNull()) {
         m_imageSize = context.imageSize();
         match.setImage(image());
         matches << match;
diff --git a/runners/youtube/youtube.cpp b/runners/youtube/youtube.cpp
index 388d5c4..4222657 100644
--- a/runners/youtube/youtube.cpp
+++ b/runners/youtube/youtube.cpp
@@ -145,7 +145,7 @@ void YoutubeSessionData::queryFinished()
 
 //                 qDebug() << "================================";
 //                 qDebug() << title << seconds << time << desc << thumbnailUrl;
-                Sprinter::QueryMatch match(runner());
+                Sprinter::QueryMatch match;
                 match.setTitle(tr("%1 (%2, %3)").arg(title, author, time));
                 match.setText(desc);
                 match.setType(Sprinter::QuerySession::VideoType);
diff --git a/sprinter/querymatch.cpp b/sprinter/querymatch.cpp
index 57b221f..c9c8cc4 100644
--- a/sprinter/querymatch.cpp
+++ b/sprinter/querymatch.cpp
@@ -16,48 +16,21 @@
  */
 
 #include "querymatch.h"
-
-#include "runner.h"
+#include "querymatch_p.h"
 
 #include <QApplication>
 #include <QClipboard>
 #include <QDebug>
 #include <QPointer>
 
-namespace Sprinter
-{
+// #include "runner.h"
+#include "runnersessiondata.h"
 
-class QueryMatch::Private : public QSharedData
+namespace Sprinter
 {
-public:
-    Private(Runner *r)
-        : runner(r),
-          type(QuerySession::UnknownType),
-          source(QuerySession::FromInternalSource),
-          precision(QuerySession::UnrelatedMatch),
-          isSearchTerm(false)
-    {
-    }
-
-    QPointer<Runner> runner;
-    QString title;
-    QString text;
-    QuerySession::MatchType type;
-    QuerySession::MatchSource source;
-    QuerySession::MatchPrecision precision;
-    QVariant data;
-    QVariant userData;
-    QImage image;
-    bool isSearchTerm;
-};
 
 QueryMatch::QueryMatch()
-    : d(new Private(0))
-{
-}
-
-QueryMatch::QueryMatch(Runner *runner)
-    : d(new Private(runner))
+    : d(new Private)
 {
 }
 
@@ -83,7 +56,7 @@ bool QueryMatch::operator==(const QueryMatch &rhs) const
 
 bool QueryMatch::isValid() const
 {
-    return d->runner;
+    return d->sessionData && d->sessionData->runner();
 }
 
 void QueryMatch::setTitle(const QString &title)
@@ -166,9 +139,14 @@ QuerySession::MatchPrecision QueryMatch::precision() const
     return d->precision;
 }
 
+RunnerSessionData *QueryMatch::sessionData() const
+{
+    return d->sessionData;
+}
+
 Runner *QueryMatch::runner() const
 {
-    return d->runner;
+    return  d->sessionData ? d->sessionData->runner() : 0;
 }
 
 void QueryMatch::setIsSearchTerm(bool searchTerm)
diff --git a/sprinter/querymatch.h b/sprinter/querymatch.h
index cd1f849..36ef609 100644
--- a/sprinter/querymatch.h
+++ b/sprinter/querymatch.h
@@ -30,22 +30,18 @@ namespace Sprinter
 {
 
 class Runner;
+class RunnerSessionData;
 
 class SPRINTER_EXPORT QueryMatch
 {
 public:
     /**
-     * Default constructor; creates an invalid match
+     * Default constructor, which creates an invalid match. A match is
+     * valid once it has been passed to a RunnerSessionData object.
      */
     QueryMatch();
 
     /**
-     * Creates a match with an associated runner. Used to create valid matches.
-     * @param runner the runner that created this match.
-     */
-    QueryMatch(Runner *runner);
-
-    /**
      * Copy constructor; valid if the other match is also valid. QueryMatch is
      * implicitly shared so this is fast
      */
@@ -172,8 +168,14 @@ public:
     QuerySession::MatchPrecision precision() const;
 
     /**
+     * @return a pointer to the sessionData associated with this match
+     * May return a null pointer if the match is invalid.
+     */
+    RunnerSessionData *sessionData() const;
+
+    /**
      * @return a pointer to the runner that created this match. May return
-     * a null pointer if the match is invalid or the runner has been deleted.
+     * a null pointer if the match is invalid.
      */
     Runner *runner() const;
 
@@ -184,6 +186,8 @@ public:
     bool sendUserDataToClipboard() const;
 
 private:
+    friend class RunnerSessionData;
+
     class Private;
     QExplicitlySharedDataPointer<Private> d;
 };
diff --git a/sprinter/runnersessiondata.cpp b/sprinter/runnersessiondata.cpp
index 7eb395c..f03210e 100644
--- a/sprinter/runnersessiondata.cpp
+++ b/sprinter/runnersessiondata.cpp
@@ -22,6 +22,7 @@
 
 #include "runner.h"
 #include "querycontext.h"
+#include "querymatch_p.h"
 #include "querysession.h"
 #include "querysession_p.h"
 #include "querysessionthread_p.h"
@@ -189,6 +190,9 @@ void RunnerSessionData::setMatches(const QVector<QueryMatch> \
&matches, const Que  return;
             }
         } else {
+            for (int i = 0; i < matches.count(); ++i) {
+                matches[i].d->sessionData = this;
+            }
             d->currentMatches = matches;
         }
 
@@ -242,6 +246,7 @@ void RunnerSessionData::updateMatches(const QVector<QueryMatch> \
                &matches)
                 qDebug() << "found update in existing matches at" << i << \
d->syncedMatches[i].data();  #endif
                 d->syncedMatches[i] = match;
+                d->syncedMatches[i].d->sessionData = this;
                 d->updatedMatchIndexes.insert(i);
                 d->session->d->matchesArrived();
                 break;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic