-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKSettingsFonbooks.cpp
More file actions
99 lines (89 loc) · 3.51 KB
/
KSettingsFonbooks.cpp
File metadata and controls
99 lines (89 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* KFritz
*
* Copyright (C) 2010-2012 Joachim Wilke <kfritz@joachim-wilke.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "KSettingsFonbooks.h"
#include <KConfigDialogManager>
#include <QListWidgetItem>
KSettingsFonbooks::KSettingsFonbooks(QWidget *parent)
:QWidget(parent) {
ui = new Ui_KSettingsFonbooks();
ui->setupUi(this);
layout()->addWidget(new KFonbooksWidget(this, ui->actionSelector));
}
KSettingsFonbooks::~KSettingsFonbooks() {
delete ui;
}
class KFonbooksWidgetListItem : public QListWidgetItem {
private:
QString id;
public:
KFonbooksWidgetListItem(const QString text, const QString id, QListWidget * parent = 0)
:QListWidgetItem(text, parent) {
this->id = id;
}
QString getId() {
return id;
}
};
KFonbooksWidget::KFonbooksWidget(QWidget *parent, KActionSelector *actionSelector)
:QWidget(parent) {
KConfigDialogManager::changedMap()->insert("KFonbooksWidget", SIGNAL(listChanged(const QStringList &)));
setObjectName(QString::fromUtf8("kcfg_PhonebookList"));
this->actionSelector = actionSelector;
connect(actionSelector, SIGNAL(added(QListWidgetItem *)), this, SLOT(listChangedSlot()));
connect(actionSelector, SIGNAL(removed(QListWidgetItem *)), this, SLOT(listChangedSlot()));
connect(actionSelector, SIGNAL(movedUp(QListWidgetItem *)), this, SLOT(listChangedSlot()));
connect(actionSelector, SIGNAL(movedDown(QListWidgetItem *)), this, SLOT(listChangedSlot()));
fritz::FonbookManager *fbm = fritz::FonbookManager::GetFonbookManager();
if (!fbm)
return;
fonbooks = fbm->getFonbooks();
for (size_t pos=0; pos < fonbooks->size(); pos++)
new KFonbooksWidgetListItem(i18n((*fonbooks)[pos]->getTitle().c_str()),
(*fonbooks)[pos]->getTechId().c_str(),
actionSelector->availableListWidget());
}
KFonbooksWidget::~KFonbooksWidget() {
}
QStringList KFonbooksWidget::getList() const {
QStringList list;
for (int pos=0; pos < actionSelector->selectedListWidget()->count(); pos++) {
KFonbooksWidgetListItem *item = static_cast<KFonbooksWidgetListItem*>(actionSelector->selectedListWidget()->item(pos));
list.append(item->getId());
}
return list;
}
void KFonbooksWidget::setList(QStringList &list) {
// move all to left
while(actionSelector->selectedListWidget()->count())
actionSelector->availableListWidget()->addItem(actionSelector->selectedListWidget()->takeItem(0));
// move selected items to right
for (int i=0; i < list.count(); i++) {
for (int j=0; j < actionSelector->availableListWidget()->count(); j++) {
if (static_cast<KFonbooksWidgetListItem*>(actionSelector->availableListWidget()->item(j))->getId() == list[i]) {
actionSelector->selectedListWidget()->addItem(actionSelector->availableListWidget()->takeItem(j));
break;
}
}
}
}
void KFonbooksWidget::listChangedSlot() {
emit listChanged(getList());
}