Fix crash on logout
[kdenetwork.git] / ksirc / NewWindowDialog.cpp
blob7d19ad00b876962bceb6a96b72e1f98d92b154c7
1 #include <kapplication.h>
2 #include <kconfig.h>
3 #include <klocale.h>
4 #include <kcombobox.h>
5 #include <khbox.h>
6 #include <qlabel.h>
7 #include <qlineedit.h>
8 #include <klineedit.h>
9 #include <kglobal.h>
10 #include "NewWindowDialog.h"
12 NewWindowDialog::NewWindowDialog(const KSircChannel &channelInfo, QWidget * parent, const char * name)
13 : KDialog(parent),
14 m_channelInfo(channelInfo)
16 setCaption(i18n("New Window For"));
17 setButtons(Ok|Cancel);
18 setDefaultButton(Ok);
19 setModal(true);
20 enableButtonSeparator(true);
21 KHBox * w = new KHBox(this);
22 setMainWidget(w);
24 QLabel * l = new QLabel(i18n("C&hannel/Nick:"), w);
26 m_combo = new KHistoryCombo(w);
27 m_combo->setFocus();
29 // we don't need duplicated channel into the list
30 m_combo->setDuplicatesEnabled( false );
32 l->setBuddy(m_combo);
34 QLabel * l2 = new QLabel(i18n("&Key:"), w);
35 m_le = new KLineEdit(w);
36 m_le->setEnabled(false);
37 l2->setBuddy(m_le);
39 connect(
40 m_combo, SIGNAL(activated(const QString &)),
41 m_combo, SLOT(addToHistory(const QString &)));
42 connect( m_combo->lineEdit(), SIGNAL(textChanged ( const QString & )),
43 this, SLOT( slotTextChanged( const QString &)));
45 KConfig *kConfig = KGlobal::config();
46 KConfigGroup group(kConfig, "Recent");
47 m_combo->setHistoryItems(group.readEntry("Channels",QStringList()));
48 slotTextChanged( m_combo->lineEdit()->text());
51 NewWindowDialog::~NewWindowDialog()
53 KConfig *kConfig = KGlobal::config();
54 KConfigGroup group(kConfig, "Recent");
55 group.writeEntry("Channels", m_combo->historyItems());
58 void NewWindowDialog::slotTextChanged( const QString &text)
60 enableButtonOk( !text.isEmpty() );
62 if(text[0] == QLatin1Char('#') || text[0] == QLatin1Char('&'))
63 m_le->setEnabled(true);
64 else
65 m_le->setEnabled(false);
69 void
70 NewWindowDialog::slotOk()
72 m_channelInfo.setChannel(m_combo->lineEdit()->text().lower());
73 if(m_le->isEnabled())
74 m_channelInfo.setKey(m_le->text());
75 emit(openTopLevel(m_channelInfo));
76 KDialog::accept();
79 #include "NewWindowDialog.moc"