23 #include "imeditordialog.h"
25 #include "imdelegate.h"
26 #include "imitemdialog.h"
28 #include <QGridLayout>
30 #include <QPushButton>
32 #include <QHeaderView>
34 #include <klocalizedstring.h>
35 #include <kmessagebox.h>
36 #include <KSharedConfig>
38 IMEditorDialog::IMEditorDialog(
QWidget *parent)
41 setCaption(i18nc(
"@title:window",
"Edit Instant Messaging Addresses"));
42 setButtons(Ok | Cancel);
46 setMainWidget(widget);
50 mAddButton =
new QPushButton(i18nc(
"@action:button",
"Add..."));
51 mEditButton =
new QPushButton(i18nc(
"@action:button",
"Edit..."));
52 mRemoveButton =
new QPushButton(i18nc(
"@action:button",
"Remove"));
53 mStandardButton =
new QPushButton(i18nc(
"@action:button",
"Set as Standard"));
65 connect(mAddButton, SIGNAL(clicked()), SLOT(slotAdd()));
66 connect(mEditButton, SIGNAL(clicked()), SLOT(slotEdit()));
67 connect(mRemoveButton, SIGNAL(clicked()), SLOT(slotRemove()));
68 connect(mStandardButton, SIGNAL(clicked()), SLOT(slotSetStandard()));
70 mModel =
new IMModel(
this);
72 mView->setModel(mModel);
73 mView->setItemDelegate(
new IMDelegate(
this));
76 this, SLOT(slotUpdateButtons()));
78 this, SLOT(slotEdit()));
83 IMEditorDialog::~IMEditorDialog()
88 void IMEditorDialog::readConfig()
90 KConfigGroup group(KGlobal::config(),
"IMEditorDialog");
91 const QSize sizeDialog = group.readEntry(
"Size",
QSize(400, 200));
97 mView->header()->restoreState(header);
100 void IMEditorDialog::writeConfig()
102 KConfigGroup group(KGlobal::config(),
"IMEditorDialog");
103 group.writeEntry(
"Size", size());
104 group.writeEntry(
"Header", mView->header()->saveState());
109 mModel->setAddresses(addresses);
114 return mModel->addresses();
117 void IMEditorDialog::slotAdd()
120 d->setCaption(i18nc(
"@title:window",
"Add IM Address"));
121 if (d->exec() == QDialog::Accepted && d != 0) {
122 IMAddress newAddress = d->address();
123 int addedRow = mModel->rowCount();
124 mModel->insertRow(addedRow);
126 mModel->setData(mModel->index(addedRow, 0), newAddress.protocol(), IMModel::ProtocolRole);
127 mModel->setData(mModel->index(addedRow, 1), newAddress.name(), Qt::EditRole);
132 void IMEditorDialog::slotEdit()
134 const int currentRow = mView->currentIndex().row();
135 if (currentRow < 0) {
140 d->setCaption(i18nc(
"@title:window",
"Edit IM Address"));
141 d->setAddress(mModel->addresses().at(currentRow));
143 if (d->exec() == QDialog::Accepted && d != 0) {
144 IMAddress editedAddress = d->address();
145 mModel->setData(mModel->index(currentRow, 0), editedAddress.protocol(),
146 IMModel::ProtocolRole);
147 mModel->setData(mModel->index(currentRow, 1), editedAddress.name(),
153 void IMEditorDialog::slotRemove()
155 const int currentRow = mView->currentIndex().row();
156 if (currentRow < 0) {
160 if (KMessageBox::warningContinueCancel(
162 i18nc(
"@info Instant messaging",
163 "Do you really want to delete the selected <resource>%1</resource> address?",
164 mModel->data(mModel->index(currentRow, 0), Qt::DisplayRole).
toString()),
165 i18nc(
"@title:window",
"Confirm Delete Resource"),
166 KStandardGuiItem::del()) != KMessageBox::Continue) {
170 mModel->removeRow(currentRow);
173 void IMEditorDialog::slotSetStandard()
175 const int currentRow = mView->currentIndex().row();
176 if (currentRow < 0) {
181 for (
int i = 0; i < mModel->rowCount(); ++i) {
183 mModel->setData(index, (index.
row() == currentRow), IMModel::IsPreferredRole);
187 void IMEditorDialog::slotUpdateButtons()
189 const QModelIndex currentIndex = mView->currentIndex();
191 mRemoveButton->setEnabled(currentIndex.
isValid());
192 mEditButton->setEnabled(currentIndex.
isValid());
194 mStandardButton->setEnabled(currentIndex.
isValid() &&
195 !mModel->data(currentIndex, IMModel::IsPreferredRole).toBool());
void setRowStretch(int row, int stretch)
char * toString(const T &value)
void setRootIsDecorated(bool show)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)