summaryrefslogtreecommitdiffstats
path: root/kbugbuster/gui/messageeditor.cpp
blob: 517ef80b0df65fccc6cac3f1ac8588ae4a120a7f (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <qcombobox.h>
#include <ktextedit.h>
#include <kinputdialog.h>
#include <qlayout.h>
#include <qlabel.h>

#include <klocale.h>
#include <kmessagebox.h>
#include <kdebug.h>

#include "kbbprefs.h"

#include "messageeditor.h"
#include <qpushbutton.h>
#include "messageeditor.moc"

MessageEditor::MessageEditor( QWidget *parent )
  : KDialogBase(Plain,i18n("Edit Message Buttons"),Ok|Cancel,Ok,parent,0,
                true,true)
{
  QFrame *topFrame = plainPage();
  QBoxLayout *topLayout = new QVBoxLayout(topFrame,0,spacingHint());

  QBoxLayout *selectionLayout = new QHBoxLayout;
  topLayout->addLayout(selectionLayout);

  QLabel *selectionLabel = new QLabel(i18n("Button:"),topFrame);
  selectionLayout->addWidget(selectionLabel);

  mSelectionCombo = new QComboBox(topFrame);
  selectionLayout->addWidget(mSelectionCombo);
  connect(mSelectionCombo,SIGNAL(activated(int)),SLOT(changeMessage()));

  QPushButton *addButton = new QPushButton(i18n("Add Button..."),topFrame);
  selectionLayout->addWidget(addButton);
  connect(addButton,SIGNAL(clicked()),SLOT(addButton()));

  QPushButton *removeButton = new QPushButton(i18n("Remove Button"),topFrame);
  selectionLayout->addWidget(removeButton);
  connect(removeButton,SIGNAL(clicked()),SLOT(removeButton()));

  mMessageEdit = new KTextEdit(topFrame);
  topLayout->addWidget(mMessageEdit,1);

  updateConfig();
}

void MessageEditor::updateConfig()
{
  mMessageButtons = KBBPrefs::instance()->mMessageButtons;

  mSelectionCombo->clear();

  QMap<QString,QString>::ConstIterator it;
  for(it = mMessageButtons.begin();it != mMessageButtons.end();++it) {
    mSelectionCombo->insertItem(it.key());
  }

  updateMessage();
}

void MessageEditor::addButton()
{
  QString txt;
  txt = KInputDialog::getText(i18n("Add Message Button"),
	i18n("Enter button name:"), QString::null,
	NULL, this );

  if ( !txt.isNull() ) {
    saveMessage();
    mSelectionCombo->insertItem(txt);
    mMessageButtons.insert(txt,"");
    mSelectionCombo->setCurrentItem(mSelectionCombo->count()-1);
    updateMessage();
  }

}

void MessageEditor::removeButton()
{
  int result = KMessageBox::warningContinueCancel(this,
      i18n("Remove the button %1?").arg(mSelectionCombo->currentText()),
      i18n("Remove"), KGuiItem( i18n("Delete"), "editdelete") );

  if (result == KMessageBox::Continue) {
    mMessageButtons.remove(mSelectionCombo->currentText());
    mSelectionCombo->removeItem(mSelectionCombo->currentItem());
    mSelectionCombo->setCurrentItem(0);
    updateMessage();
  }
}

void MessageEditor::changeMessage()
{
  saveMessage();
  updateMessage();
}

void MessageEditor::updateMessage()
{
  mCurrentButton = mSelectionCombo->currentText();

  mMessageEdit->setText(mMessageButtons[mCurrentButton]);
}

void MessageEditor::saveMessage()
{
  mMessageButtons.replace(mCurrentButton,mMessageEdit->text());
}

void MessageEditor::slotOk()
{
  saveMessage();

  KBBPrefs::instance()->mMessageButtons = mMessageButtons;
  accept();
}