~ubuntu-branches/debian/stretch/psi-plus/stretch

« back to all changes in this revision

Viewing changes to src/plugins/generic/watcherplugin/model.cpp

  • Committer: Package Import Robot
  • Author(s): Boris Pek
  • Date: 2013-10-23 02:42:20 UTC
  • mfrom: (1.4.7)
  • Revision ID: package-import@ubuntu.com-20131023024220-bk2hyoenqkwfhpgw
Tags: 0.16.242-1
* New upstream release:
  fixed the problem of initialization of private conversation when both
  sides use libotr 4.0.x. (Closes: #724880)
* Update debian/watch: sources were moved.
* Delete psi-plus-content-downloader package and update all related files.
  This plugin is in psi-plus-plugins package now.
* Update debian/control:
  - remove all currently unneeded Replaces and Breaks fields
  - add build dependency on libidn11-dev
* Update debian/rules: simplify get-orig-source section.
* Update debian/copyright:
  - update Source field due to changes in sources location
  - remove copyright holders whose code was deleted from source tree
    (bundled libidn library was removed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include "model.h"
22
22
 
23
 
Model::Model(const QStringList& watchedJids_, const QStringList& Sounds_, QObject* parent)
24
 
        : QAbstractTableModel(parent)
25
 
        , watchedJids(watchedJids_)
26
 
        , sounds(Sounds_)
 
23
Model::Model(const QStringList& watchedJids_, const QStringList& Sounds_, const QStringList& enabledJids_, QObject* parent)
 
24
        : QAbstractTableModel(parent)
 
25
        , watchedJids(watchedJids_)
 
26
        , sounds(Sounds_)
 
27
        , enabledJids(enabledJids_)
27
28
{
28
29
        headers << tr("")
29
30
                        << tr("Watch for JIDs")
31
32
                        << tr("")
32
33
                        << tr("");
33
34
 
34
 
        unselectAll();
35
 
 
36
35
        tmpWatchedJids_ = watchedJids;
37
36
        tmpSounds_ = sounds;
 
37
 
 
38
        foreach (QString enabledJid, enabledJids_) {
 
39
                tmpEnabledJids_ << (enabledJid == "true" ? true : false);
 
40
        }
38
41
}
39
42
 
40
43
QVariant Model::headerData ( int section, Qt::Orientation orientation, int role) const
41
44
{
42
45
        if (role == Qt::DisplayRole) {
43
 
                if (orientation == Qt::Horizontal) {
44
 
                        return headers.at(section);
45
 
                } else {
46
 
                        return section+1;
47
 
                }
48
 
        } else
 
46
                if (orientation == Qt::Horizontal) {
 
47
                        return headers.at(section);
 
48
                } else {
 
49
                        return section+1;
 
50
                }
 
51
        } else
49
52
                return QVariant();
50
53
}
51
54
 
80
83
 
81
84
        int i = index.column();
82
85
        switch(i) {
83
 
        case(0):
84
 
                if (role == Qt::CheckStateRole) {
85
 
                        return selected.at(index.row()) ? 2:0;
86
 
                } else if (role == Qt::TextAlignmentRole) {
87
 
                        return (int)(Qt::AlignRight | Qt::AlignVCenter);
88
 
                } else if (role == Qt::DisplayRole)
89
 
                        return QVariant("");
90
 
             case(1):
91
 
                if (role == Qt::TextAlignmentRole) {
92
 
                        return (int)(Qt::AlignRight | Qt::AlignVCenter);
93
 
                } else if (role == Qt::DisplayRole)
 
86
        case 0:
 
87
                if (role == Qt::CheckStateRole) {
 
88
                        return tmpEnabledJids_.at(index.row()) ? 2:0;
 
89
                } else if (role == Qt::TextAlignmentRole) {
 
90
                        return (int)(Qt::AlignRight | Qt::AlignVCenter);
 
91
                } else if (role == Qt::DisplayRole)
 
92
                        return QVariant("");
 
93
        case 1:
 
94
                if (role == Qt::TextAlignmentRole) {
 
95
                        return (int)(Qt::AlignRight | Qt::AlignVCenter);
 
96
                } else if (role == Qt::DisplayRole)
94
97
                        return QVariant(tmpWatchedJids_.at(index.row()));
95
 
             case(2):
96
 
                if (role == Qt::TextAlignmentRole) {
97
 
                        return (int)(Qt::AlignRight | Qt::AlignVCenter);
98
 
                } else if (role == Qt::DisplayRole)
99
 
                        return QVariant(tmpSounds_.at(index.row()));
100
 
             case(3):
101
 
                if (role == Qt::TextAlignmentRole) {
102
 
                        return (int)(Qt::AlignRight | Qt::AlignVCenter);
103
 
                } else if (role == Qt::DisplayRole)
104
 
                        return QVariant();
105
 
             case(4):
106
 
                if (role == Qt::TextAlignmentRole) {
107
 
                        return (int)(Qt::AlignRight | Qt::AlignVCenter);
108
 
                } else if (role == Qt::DisplayRole)
109
 
                        return QVariant();
110
 
        }
 
98
        case 2:
 
99
                if (role == Qt::TextAlignmentRole) {
 
100
                        return (int)(Qt::AlignRight | Qt::AlignVCenter);
 
101
                } else if (role == Qt::DisplayRole)
 
102
                        return QVariant(tmpSounds_.at(index.row()));
 
103
        case 3:
 
104
                if (role == Qt::TextAlignmentRole) {
 
105
                        return (int)(Qt::AlignRight | Qt::AlignVCenter);
 
106
                } else if (role == Qt::DisplayRole)
 
107
                        return QVariant();
 
108
        case 4:
 
109
                if (role == Qt::TextAlignmentRole) {
 
110
                        return (int)(Qt::AlignRight | Qt::AlignVCenter);
 
111
                } else if (role == Qt::DisplayRole)
 
112
                        return QVariant();
 
113
        }
111
114
        return QVariant();
112
115
}
113
116
 
142
145
 
143
146
        int column = index.column();
144
147
        if(column == 0) {
145
 
                bool b = selected.at( index.row() );
 
148
                bool b = tmpEnabledJids_.at( index.row() );
146
149
                switch(value.toInt()) {
147
 
                case(0):
148
 
                        selected.replace( index.row(), false);
149
 
                        break;
150
 
                case(2):
151
 
                        selected.replace( index.row(), true);
152
 
                        break;
153
 
                case(3):
154
 
                        selected.replace( index.row(), !b);
 
150
                case 0:
 
151
                        tmpEnabledJids_.replace( index.row(), false);
 
152
                        break;
 
153
                case 2:
 
154
                        tmpEnabledJids_.replace( index.row(), true);
 
155
                        break;
 
156
                case 3:
 
157
                        tmpEnabledJids_.replace( index.row(), !b);
155
158
                        break;
156
159
                }
157
160
        }
171
174
        statuses.insert(jid, status);
172
175
}
173
176
 
174
 
void Model::deleteSelected()
 
177
void Model::deleteRows(const QModelIndexList &indexList)
175
178
{
176
 
        emit layoutAboutToBeChanged ();
 
179
        QList<bool> selected;
 
180
        for (int i = 0; i < tmpWatchedJids_.size(); i++) {
 
181
                selected << false;
 
182
        }
 
183
 
 
184
        foreach (QModelIndex index, indexList) {
 
185
                selected[index.row()] = true;
 
186
        }
 
187
 
177
188
        QStringList tmpJids, tmpSounds;
178
 
        for(int i=0; i<watchedJids.size(); i++) {
179
 
                if(!selected.at(i)) {
180
 
                        tmpJids.append(watchedJids.at(i));
181
 
                        tmpSounds.append(sounds.at(i));
 
189
        QList<bool> tmpEnabledJids;
 
190
        for (int i = tmpWatchedJids_.size() - 1; i >= 0; i--) {
 
191
                if(selected.at(i)) {
 
192
                        removeRow(i);
182
193
                }
183
194
        }
184
 
 
185
 
        tmpWatchedJids_.clear();
186
 
        tmpSounds_.clear();
187
 
        tmpWatchedJids_ = tmpJids;
188
 
        tmpSounds_ = tmpSounds;
189
 
 
190
 
        unselectAll();
 
195
}
 
196
 
 
197
bool Model::removeRows(int row, int count, const QModelIndex &parent)
 
198
{
 
199
        beginRemoveRows(parent, row, row + count - 1);
 
200
        for (int i = 0; i < count; i++) {
 
201
                tmpWatchedJids_.removeAt(row);
 
202
                tmpSounds_.removeAt(row);
 
203
                tmpEnabledJids_.removeAt(row);
 
204
        }
 
205
        endRemoveRows();
 
206
        return true;
191
207
}
192
208
 
193
209
void Model::reset()
194
210
{
195
211
        tmpWatchedJids_ = watchedJids;
196
212
        tmpSounds_ = sounds;
197
 
        unselectAll();
198
 
}
199
 
 
200
 
void Model::selectAll()
201
 
{
202
 
        selected.clear();
203
 
 
204
 
        foreach(QString jid, tmpWatchedJids_) {
205
 
                Q_UNUSED(jid);
206
 
                selected.append(true);
207
 
        }
208
 
 
209
 
        emit layoutChanged();
210
 
}
211
 
 
212
 
void Model::unselectAll()
213
 
{
214
 
        selected.clear();
215
 
 
216
 
        foreach(QString jid, watchedJids) {
217
 
                selected.append(false);
218
 
        }
219
 
 
220
 
        emit layoutChanged();
 
213
 
 
214
        tmpEnabledJids_.clear();
 
215
        foreach (QString enabledJid, enabledJids) {
 
216
                tmpEnabledJids_ << (enabledJid == "true" ? true : false);
 
217
        }
221
218
}
222
219
 
223
220
void Model::addRow(const QString& jid)
226
223
        tmpWatchedJids_ << jid;
227
224
        tmpSounds_ << "";
228
225
 
229
 
        if(!jid.isEmpty()) {      //вызов происходит из меню контакта
 
226
        if(!jid.isEmpty()) {      //вызов происходит из меню контакта
230
227
                watchedJids.append(jid);
231
228
                sounds.append("");
 
229
                enabledJids.append("true");
232
230
        }
233
231
 
234
 
        selected.append(false);
 
232
        tmpEnabledJids_.append(true);
235
233
        endInsertRows();
236
234
}
237
235
 
244
242
        sounds.removeAt(index);
245
243
        tmpWatchedJids_.removeAt(index);
246
244
        tmpSounds_.removeAt(index);
247
 
        selected.removeAt(index);
 
245
        tmpEnabledJids_.removeAt(index);
248
246
 
249
247
        emit layoutChanged();
250
248
}
253
251
{
254
252
        watchedJids =  tmpWatchedJids_;
255
253
        sounds = tmpSounds_;
 
254
        enabledJids.clear();
 
255
        foreach (bool enabledJid, tmpEnabledJids_) {
 
256
                enabledJids << (enabledJid ? "true" : "false");
 
257
        }
256
258
}
257
259
 
258
260
QString Model::statusByJid(const QString& jid) const
284
286
{
285
287
        return sounds;
286
288
}
 
289
 
 
290
QStringList Model::getEnabledJids() const
 
291
{
 
292
        return enabledJids;
 
293
}
 
294
 
 
295
void Model::setJidEnabled(const QString& jid, bool enabled)
 
296
{
 
297
        // Do nothing if need to disable jid which is not in watcher list
 
298
        if (!getWatchedJids().contains(jid, Qt::CaseInsensitive) && !enabled) {
 
299
                return;
 
300
        }
 
301
 
 
302
        // Before add Jid to watcher list
 
303
        if (!getWatchedJids().contains(jid, Qt::CaseInsensitive)) {
 
304
                addRow(jid);
 
305
        }
 
306
 
 
307
        QModelIndex ind = index(indexByJid(jid), 0);
 
308
        setData(ind, enabled ? 2 : 0);
 
309
}
 
310
 
 
311
bool Model::jidEnabled(const QString& jid)
 
312
{
 
313
        // watcher doesn't applied for this jid
 
314
        if (!getWatchedJids().contains(jid, Qt::CaseInsensitive )) {
 
315
                return false;
 
316
        }
 
317
 
 
318
        QModelIndex ind = index(indexByJid(jid), 0);
 
319
        return (data(ind, Qt::CheckStateRole) == 2) ? true : false;
 
320
}