2
* Copyright (C) 2010 Canonical, Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#include "windowslist.h"
20
#include "windowinfo.h"
22
#include "bamf-matcher.h"
23
#include "bamf-window.h"
24
#include "bamf-application.h"
26
WindowsList::WindowsList(QObject *parent) :
27
QAbstractListModel(parent), m_applicationId(0),
28
m_loaded(false), m_lastActiveWindow(NULL)
30
QHash<int, QByteArray> roles;
35
WindowsList::~WindowsList()
37
qDeleteAll(m_windows);
40
int WindowsList::rowCount(const QModelIndex &parent) const
44
return m_windows.size();
47
QVariant WindowsList::data(const QModelIndex &index, int role) const
54
WindowInfo *info = m_windows.at(index.row());
55
return QVariant::fromValue(info);
58
void WindowsList::load(unsigned long applicationId)
60
if (m_loaded && m_applicationId == applicationId) {
64
BamfMatcher &matcher = BamfMatcher::get_default();
65
QList<BamfApplication*> applications;
67
if (applicationId == 0) {
68
/* List the windows of all the applications */
69
BamfApplicationList *allapplications = matcher.applications();
70
for (int i = 0; i < allapplications->size(); i++) {
71
applications.append(allapplications->at(i));
74
/* List the windows of the application that has for group leader the window
75
with XID applicationId */
76
applications.append(matcher.application_for_xid(applicationId));
79
BamfWindow* activeWindow = matcher.active_window();
81
/* Build a list of windowInfos for windows that are 'user_visible' according to BAMF */
82
QList<WindowInfo*> newWindows;
84
Q_FOREACH (BamfApplication* application, applications) {
85
if (!application->user_visible()) {
89
BamfWindowList *bamfWindows = application->windows();
90
for (int i = 0; i < bamfWindows->size(); i++) {
91
BamfWindow* window = bamfWindows->at(i);
92
if (!window->user_visible()) {
96
WindowInfo *info = new WindowInfo(window->xid());
97
newWindows.append(info);
99
if (activeWindow != NULL && window->xid() == activeWindow->xid()) {
100
m_lastActiveWindow = info;
105
qDebug() << "Matched" << newWindows.count() << "Windows in" << applications.count() << "Applications";
107
if (m_windows.count() > 0) {
108
beginRemoveRows(QModelIndex(), 0, m_windows.count() - 1);
109
qDeleteAll(m_windows);
114
if (newWindows.count() > 0) {
115
beginInsertRows(QModelIndex(), 0, newWindows.count() - 1);
116
m_windows.append(newWindows);
120
m_applicationId = applicationId;
123
Q_EMIT countChanged(m_windows.count());
124
Q_EMIT lastActiveWindowChanged(m_lastActiveWindow);
127
void WindowsList::unload()
129
beginRemoveRows(QModelIndex(), 0, m_windows.count() - 1);
130
qDeleteAll(m_windows);
136
Q_EMIT countChanged(m_windows.count());
139
WindowInfo* WindowsList::lastActiveWindow() const {
140
return m_lastActiveWindow;