summaryrefslogtreecommitdiffstats
path: root/ksirc/NewWindowDialog.cpp
blob: f7cf4f6914dd0a282a00a560898333898e4d94c1 (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
#include <tdeapplication.h>
#include <tdeconfig.h>
#include <tdelocale.h>
#include <kcombobox.h>
#include <tqhbox.h>
#include <tqlabel.h>
#include <tqlineedit.h>
#include <klineedit.h>
#include "NewWindowDialog.h"

NewWindowDialog::NewWindowDialog(const KSircChannel &channelInfo, TQWidget * parent, const char * name)
    : KDialogBase(parent, name, true, i18n("New Window For"), Ok|Cancel, Ok, true),
      m_channelInfo(channelInfo)
{
  TQHBox * w = makeHBoxMainWidget();

  TQLabel * l = new TQLabel(i18n("C&hannel/Nick:"), w);

  m_combo = new KHistoryCombo(w);
  m_combo->setFocus();

  // we don't need duplicated channel into the list
  m_combo->setDuplicatesEnabled( false );

  l->setBuddy(m_combo);

  TQLabel * l2 = new TQLabel(i18n("&Key:"), w);
  m_le = new KLineEdit(w);
  m_le->setEnabled(false);
  l2->setBuddy(m_le);

  connect(
      m_combo, TQT_SIGNAL(activated(const TQString &)),
      m_combo, TQT_SLOT(addToHistory(const TQString &)));
  connect( m_combo->lineEdit(), TQT_SIGNAL(textChanged ( const TQString & )),
	   this, TQT_SLOT( slotTextChanged( const TQString &)));

  TDEConfig *kConfig = kapp->config();
  TDEConfigGroupSaver saver(kConfig, "Recent");
  m_combo->setHistoryItems(kConfig->readListEntry("Channels"));
  slotTextChanged( m_combo->lineEdit()->text());
}

NewWindowDialog::~NewWindowDialog()
{
  TDEConfig *kConfig = kapp->config();
  TDEConfigGroupSaver saver(kConfig, "Recent");
  kConfig->writeEntry("Channels", m_combo->historyItems());
}

void NewWindowDialog::slotTextChanged( const TQString &text)
{
  enableButtonOK( !text.isEmpty() );

  if(text[0] == "#" || text[0] == "&")
    m_le->setEnabled(true);
  else
    m_le->setEnabled(false);
}


  void
NewWindowDialog::slotOk()
{
  m_channelInfo.setChannel(m_combo->lineEdit()->text().lower());
  if(m_le->isEnabled())
    m_channelInfo.setKey(m_le->text());
  emit(openTopLevel(m_channelInfo));
  KDialogBase::slotOk();
}

#include "NewWindowDialog.moc"