KWin activities usage ported to the new library paradigm
Since the KActivities library now keeps an internal cache (and is non-blocking), there is no point in thread-based information fetching. BUG: 335396 REVIEW: 118443icc-effect-5.14.5
parent
b83f63edf2
commit
b995c9da23
|
@ -41,7 +41,6 @@ Activities::Activities(QObject *parent)
|
|||
{
|
||||
connect(m_controller, &KActivities::Controller::activityRemoved, this, &Activities::slotRemoved);
|
||||
connect(m_controller, &KActivities::Controller::activityRemoved, this, &Activities::removed);
|
||||
connect(m_controller, &KActivities::Controller::activityAdded, this, &Activities::slotAdded);
|
||||
connect(m_controller, &KActivities::Controller::activityAdded, this, &Activities::added);
|
||||
connect(m_controller, &KActivities::Controller::currentActivityChanged, this, &Activities::slotCurrentChanged);
|
||||
}
|
||||
|
@ -66,14 +65,8 @@ void Activities::slotCurrentChanged(const QString &newActivity)
|
|||
emit currentChanged(newActivity);
|
||||
}
|
||||
|
||||
void Activities::slotAdded(const QString &activity)
|
||||
{
|
||||
m_all << activity;
|
||||
}
|
||||
|
||||
void Activities::slotRemoved(const QString &activity)
|
||||
{
|
||||
m_all.removeOne(activity);
|
||||
foreach (Client * client, Workspace::self()->clientList()) {
|
||||
client->setOnActivity(activity, false);
|
||||
}
|
||||
|
@ -122,7 +115,7 @@ bool Activities::start(const QString &id)
|
|||
return false; //ksmserver doesn't queue requests (yet)
|
||||
}
|
||||
|
||||
if (!m_all.contains(id)) {
|
||||
if (!all().contains(id)) {
|
||||
return false; //bogus id
|
||||
}
|
||||
|
||||
|
@ -146,7 +139,6 @@ bool Activities::stop(const QString &id)
|
|||
}
|
||||
|
||||
//ugly hack to avoid dbus deadlocks
|
||||
update(true, false);
|
||||
QMetaObject::invokeMethod(this, "reallyStop", Qt::QueuedConnection, Q_ARG(QString, id));
|
||||
//then lie and assume it worked.
|
||||
return true;
|
||||
|
@ -184,7 +176,7 @@ void Activities::reallyStop(const QString &id)
|
|||
foreach (const QString & activityId, activities) {
|
||||
if (activityId == id) {
|
||||
saveSessionIds << sessionId;
|
||||
} else if (m_running.contains(activityId)) {
|
||||
} else if (running().contains(activityId)) {
|
||||
dontCloseSessionIds << sessionId;
|
||||
}
|
||||
}
|
||||
|
@ -213,72 +205,4 @@ void Activities::reallyStop(const QString &id)
|
|||
}
|
||||
}
|
||||
|
||||
//BEGIN threaded activity list fetching
|
||||
typedef QPair<QStringList*, QStringList> AssignedList;
|
||||
typedef QPair<QString, QStringList> CurrentAndList;
|
||||
|
||||
static AssignedList
|
||||
fetchActivityList(KActivities::Controller *controller, QStringList *target, bool running) // could be member function, but actually it's much simpler this way
|
||||
{
|
||||
return AssignedList(target, running ? controller->activities(KActivities::Info::Running) :
|
||||
controller->activities());
|
||||
}
|
||||
|
||||
static CurrentAndList
|
||||
fetchActivityListAndCurrent(KActivities::Controller *controller)
|
||||
{
|
||||
QStringList l = controller->activities();
|
||||
QString c = controller->currentActivity();
|
||||
return CurrentAndList(c, l);
|
||||
}
|
||||
|
||||
void Activities::update(bool running, bool updateCurrent, QObject *target, QString slot)
|
||||
{
|
||||
if (updateCurrent) {
|
||||
QFutureWatcher<CurrentAndList>* watcher = new QFutureWatcher<CurrentAndList>;
|
||||
connect( watcher, SIGNAL(finished()), SLOT(handleReply()) );
|
||||
if (!slot.isEmpty()) {
|
||||
watcher->setProperty("activityControllerCallback", slot); // "activity reply trigger"
|
||||
watcher->setProperty("activityControllerCallbackTarget", qVariantFromValue((void*)target));
|
||||
}
|
||||
watcher->setFuture(QtConcurrent::run(fetchActivityListAndCurrent, m_controller));
|
||||
} else {
|
||||
QFutureWatcher<AssignedList>* watcher = new QFutureWatcher<AssignedList>;
|
||||
connect(watcher, SIGNAL(finished()), SLOT(handleReply()));
|
||||
if (!slot.isEmpty()) {
|
||||
watcher->setProperty("activityControllerCallback", slot); // "activity reply trigger"
|
||||
watcher->setProperty("activityControllerCallbackTarget", qVariantFromValue((void*)target));
|
||||
}
|
||||
QStringList *target = running ? &m_running : &m_all;
|
||||
watcher->setFuture(QtConcurrent::run(fetchActivityList, m_controller, target, running));
|
||||
}
|
||||
}
|
||||
|
||||
void Activities::handleReply()
|
||||
{
|
||||
QObject *watcherObject = 0;
|
||||
if (QFutureWatcher<AssignedList>* watcher = dynamic_cast< QFutureWatcher<AssignedList>* >(sender())) {
|
||||
// we carry over the to-be-updated StringList member as pointer in the threaded return
|
||||
*(watcher->result().first) = watcher->result().second;
|
||||
watcherObject = watcher;
|
||||
}
|
||||
|
||||
if (!watcherObject) {
|
||||
if (QFutureWatcher<CurrentAndList>* watcher = dynamic_cast< QFutureWatcher<CurrentAndList>* >(sender())) {
|
||||
m_all = watcher->result().second;
|
||||
slotCurrentChanged(watcher->result().first);
|
||||
watcherObject = watcher;
|
||||
}
|
||||
}
|
||||
|
||||
if (watcherObject) {
|
||||
QString slot = watcherObject->property("activityControllerCallback").toString();
|
||||
QObject *target = static_cast<QObject*>(watcherObject->property("activityControllerCallbackTarget").value<void*>());
|
||||
watcherObject->deleteLater(); // has done it's job
|
||||
if (!slot.isEmpty())
|
||||
QMetaObject::invokeMethod(target, slot.toAscii().data(), Qt::DirectConnection);
|
||||
}
|
||||
}
|
||||
//END threaded activity list fetching
|
||||
|
||||
} // namespace
|
||||
|
|
21
activities.h
21
activities.h
|
@ -25,6 +25,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <QObject>
|
||||
#include <QStringList>
|
||||
|
||||
#include <kactivities/controller.h>
|
||||
|
||||
namespace KActivities {
|
||||
class Controller;
|
||||
}
|
||||
|
@ -42,7 +44,6 @@ public:
|
|||
|
||||
bool stop(const QString &id);
|
||||
bool start(const QString &id);
|
||||
void update(bool running, bool updateCurrent, QObject *target = NULL, QString slot = QString());
|
||||
void setCurrent(const QString &activity);
|
||||
/**
|
||||
* Adds/removes client \a c to/from \a activity.
|
||||
|
@ -51,8 +52,8 @@ public:
|
|||
*/
|
||||
void toggleClientOnActivity(Client* c, const QString &activity, bool dont_activate);
|
||||
|
||||
const QStringList &running() const;
|
||||
const QStringList &all() const;
|
||||
QStringList running() const;
|
||||
QStringList all() const;
|
||||
const QString ¤t() const;
|
||||
const QString &previous() const;
|
||||
|
||||
|
@ -79,25 +80,21 @@ Q_SIGNALS:
|
|||
|
||||
private Q_SLOTS:
|
||||
void slotRemoved(const QString &activity);
|
||||
void slotAdded(const QString &activity);
|
||||
void slotCurrentChanged(const QString &newActivity);
|
||||
void reallyStop(const QString &id); //dbus deadlocks suck
|
||||
void handleReply();
|
||||
|
||||
private:
|
||||
QStringList m_running;
|
||||
QStringList m_all;
|
||||
QString m_current;
|
||||
QString m_previous;
|
||||
QString m_current;
|
||||
KActivities::Controller *m_controller;
|
||||
|
||||
KWIN_SINGLETON(Activities)
|
||||
};
|
||||
|
||||
inline
|
||||
const QStringList &Activities::all() const
|
||||
QStringList Activities::all() const
|
||||
{
|
||||
return m_all;
|
||||
return m_controller->activities();
|
||||
}
|
||||
|
||||
inline
|
||||
|
@ -113,9 +110,9 @@ const QString &Activities::previous() const
|
|||
}
|
||||
|
||||
inline
|
||||
const QStringList &Activities::running() const
|
||||
QStringList Activities::running() const
|
||||
{
|
||||
return m_running;
|
||||
return m_controller->activities(KActivities::Info::Running);
|
||||
}
|
||||
|
||||
inline
|
||||
|
|
|
@ -391,9 +391,6 @@ void UserActionsMenu::menuAboutToShow()
|
|||
} else {
|
||||
initScreenPopup();
|
||||
}
|
||||
#ifdef KWIN_BUILD_ACTIVITIES
|
||||
Activities::self()->update(true, false, this, "showHideActivityMenu");
|
||||
#endif
|
||||
|
||||
m_menu->setPalette(m_client.data()->palette());
|
||||
m_resizeOperation->setEnabled(m_client.data()->isResizable());
|
||||
|
@ -437,6 +434,8 @@ void UserActionsMenu::menuAboutToShow()
|
|||
delete m_scriptsMenu;
|
||||
m_scriptsMenu = NULL;
|
||||
}
|
||||
|
||||
showHideActivityMenu();
|
||||
}
|
||||
|
||||
void UserActionsMenu::showHideActivityMenu()
|
||||
|
|
|
@ -295,9 +295,6 @@ void Workspace::init()
|
|||
}
|
||||
if (!VirtualDesktopManager::self()->setCurrent(initial_desktop))
|
||||
VirtualDesktopManager::self()->setCurrent(1);
|
||||
#ifdef KWIN_BUILD_ACTIVITIES
|
||||
Activities::self()->update(false, true);
|
||||
#endif
|
||||
|
||||
reconfigureTimer.setSingleShot(true);
|
||||
updateToolWindowsTimer.setSingleShot(true);
|
||||
|
|
Loading…
Reference in New Issue