24 #include "improtocols.h"
27 #include <klocalizedstring.h>
29 IMAddress::IMAddress()
35 IMAddress::IMAddress(
const QString &protocol,
const QString &name,
bool preferred)
38 , mPreferred(preferred)
42 void IMAddress::setProtocol(
const QString &protocol)
47 QString IMAddress::protocol()
const
52 void IMAddress::setName(
const QString &name)
62 void IMAddress::setPreferred(
bool preferred)
64 mPreferred = preferred;
67 bool IMAddress::preferred()
const
72 IMModel::IMModel(
QObject *parent)
83 emit layoutAboutToBeChanged();
85 mAddresses = addresses;
98 return createIndex(row, column);
113 if (index.
row() < 0 || index.
row() >= mAddresses.count()) {
121 const IMAddress &address = mAddresses[index.
row()];
123 if (role == Qt::DisplayRole) {
124 if (index.
column() == 0) {
125 return IMProtocols::self()->name(address.protocol());
127 return address.name();
131 if (role == Qt::DecorationRole) {
132 if (index.
column() == 1) {
136 return KIcon(IMProtocols::self()->icon(address.protocol()));
139 if (role == Qt::EditRole) {
140 if (index.
column() == 0) {
141 return address.protocol();
143 return address.name();
147 if (role == ProtocolRole) {
148 return address.protocol();
151 if (role == IsPreferredRole) {
152 return address.preferred();
164 if (index.
row() < 0 || index.
row() >= mAddresses.count()) {
172 IMAddress &address = mAddresses[index.
row()];
174 if (role == Qt::EditRole) {
175 if (index.
column() == 1) {
177 emit dataChanged(index, index);
182 if (role == ProtocolRole) {
183 address.setProtocol(value.
toString());
184 emit dataChanged(this->index(index.
row(), 0), this->index(index.
row(), 1));
188 if (role == IsPreferredRole) {
189 address.setPreferred(value.
toBool());
190 emit dataChanged(this->index(index.
row(), 0), this->index(index.
row(), 1));
197 QVariant IMModel::headerData(
int section, Qt::Orientation orientation,
int role)
const
199 if (section < 0 || section > 1) {
203 if (orientation != Qt::Horizontal) {
207 if (role != Qt::DisplayRole) {
212 return i18nc(
"instant messaging protocol",
"Protocol");
214 return i18nc(
"instant messaging address",
"Address");
220 if (!index.
isValid() || index.
row() < 0 || index.
row() >= mAddresses.count()) {
225 return (parentFlags | Qt::ItemIsEnabled | Qt::ItemIsEditable);
228 int IMModel::columnCount(
const QModelIndex &parent)
const
237 int IMModel::rowCount(
const QModelIndex &parent)
const
240 return mAddresses.count();
246 bool IMModel::insertRows(
int row,
int count,
const QModelIndex &parent)
252 beginInsertRows(parent, row, row + count - 1);
253 for (
int i = 0; i < count; ++i) {
254 mAddresses.insert(row, IMAddress());
261 bool IMModel::removeRows(
int row,
int count,
const QModelIndex &parent)
267 beginRemoveRows(parent, row, row + count - 1);
268 for (
int i = 0; i < count; ++i) {
269 mAddresses.remove(row);
virtual Qt::ItemFlags flags(const QModelIndex &index) const