summaryrefslogtreecommitdiffstats
path: root/src/modules/channelsjoin/channelsjoinwindow.cpp
blob: 8c5e71e06c39b2a84bab9c877c22ad1c104833b3 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
//=============================================================================
//
//   File : channelsjoinwindow.cpp
//   Creation date : Thu Nov 6 2001 12:41:18 by Juanjo �varez
//
//   This file is part of the KVirc irc client distribution
//   Copyright (C) 2001-2003 Szymon Stefanek (pragma at kvirc dot net)
//
//   This program is FREE software. You can redistribute it and/or
//   modify it under the linkss of the GNU General Public License
//   as published by the Free Software Foundation; either version 2
//   of the License, or (at your opinion) 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 "channelsjoinwindow.h"

#include "kvi_locale.h"
#include "kvi_options.h"
#include "kvi_selectors.h"
#include "kvi_app.h"

#include "kvi_string.h"
#include "kvi_iconmanager.h"
#include "kvi_console.h"
#include "kvi_regchan.h"
#include "kvi_kvs_script.h"

#include <tqlabel.h>
#include <tqlineedit.h>
#include "kvi_tal_listview.h"
#include <kvi_tal_groupbox.h>
#include <tqlayout.h>
#include <tqcheckbox.h>
#include <tqpushbutton.h>
	#include <tqheader.h>
#include <tqevent.h>

extern KviChannelsJoinWindow * g_pChannelsWindow;
extern TQRect                   g_rectChannelsJoinGeometry;
// kvi_app.cpp
extern KVIRC_API KviRegisteredChannelDataBase * g_pRegisteredChannelDataBase;


KviChannelsJoinWindow::KviChannelsJoinWindow(TQWidget * par, const char * name) 
: TQDialog(par,name)
{
	m_pConsole=0;
	setCaption(__tr2qs("Join Channels"));

	setIcon(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_CHANNEL)));

	TQGridLayout * g = new TQGridLayout(this,4,2,4,8);
	
	m_pListView = new KviTalListView(this);
	m_pListView->addColumn(__tr2qs("Channel"));
	m_pListView->setRootIsDecorated(true);
	m_pListView->setSelectionMode(KviTalListView::Single);
	g->addMultiCellWidget(m_pListView,0,0,0,1);
	connect(m_pListView,TQT_SIGNAL(clicked(KviTalListViewItem *)),this,TQT_SLOT(itemClicked(KviTalListViewItem *)));
	connect(m_pListView,TQT_SIGNAL(doubleClicked(KviTalListViewItem *)),this,TQT_SLOT(itemDoubleClicked(KviTalListViewItem *)));


	m_pGroupBox = new KviTalGroupBox(2,TQt::Horizontal,__tr2qs("Channel" ),this);
	TQString szMsg = __tr2qs("Name");
	szMsg.append(":");
	TQLabel * l = new TQLabel(szMsg,m_pGroupBox);

	m_pChannelEdit = new TQLineEdit(m_pGroupBox); 
	connect(m_pChannelEdit,TQT_SIGNAL(returnPressed()), this, TQT_SLOT(editReturnPressed()));
	connect(m_pChannelEdit,TQT_SIGNAL(textChanged(const TQString &)),this,TQT_SLOT(editTextChanged(const TQString &)));

	szMsg = __tr2qs("Password");
	szMsg.append(":");
	l = new TQLabel(szMsg,m_pGroupBox);

	m_pPass = new TQLineEdit(m_pGroupBox);
	m_pPass->setEchoMode(TQLineEdit::Password);

	g->addMultiCellWidget(m_pGroupBox,1,1,0,1);


	m_pJoinButton = new TQPushButton(__tr2qs("&Join"),this);
	// Join on return pressed
	m_pJoinButton->setDefault(true);
	connect(m_pJoinButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(joinClicked()));

	g->addMultiCellWidget(m_pJoinButton,2,2,0,1,AlignHCenter);


	m_pShowAtStartupCheck = new KviStyledCheckBox(__tr2qs("Show this window after connecting"),this);
	m_pShowAtStartupCheck->setChecked(KVI_OPTION_BOOL(KviOption_boolShowChannelsJoinOnIrc));
	g->addWidget(m_pShowAtStartupCheck,3,0);


	TQPushButton * cancelButton = new TQPushButton(__tr2qs("Close"),this);
	connect(cancelButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(cancelClicked()));

	g->addWidget(cancelButton,3,1);

/*
	KviTalHBox * hb = new KviTalHBox(this);
	hb->setSpacing(4);
	
	TQPushButton * namesButton = new TQPushButton("/names", hb);
	connect(namesButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(namesClicked()));
	TQPushButton * whoButton = new TQPushButton("/who", hb);
	connect(whoButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(whoClicked()));

	g->addWidget(hb,2,0);
*/

	g->setRowStretch(0,1);
	g->setColStretch(0,1);

	fillListView();

	if(g_rectChannelsJoinGeometry.y() < 5)g_rectChannelsJoinGeometry.setY(5);

	resize(g_rectChannelsJoinGeometry.width(),g_rectChannelsJoinGeometry.height());
	move(g_rectChannelsJoinGeometry.x(),g_rectChannelsJoinGeometry.y());

	enableJoin();
}

KviChannelsJoinWindow::~KviChannelsJoinWindow()
{
	KVI_OPTION_BOOL(KviOption_boolShowChannelsJoinOnIrc) = m_pShowAtStartupCheck->isChecked();

	g_rectChannelsJoinGeometry = TQRect(pos().x(),pos().y(),size().width(),size().height());
	g_pChannelsWindow = 0;
}

void KviChannelsJoinWindow::setConsole(KviConsole  * pConsole)
{
	m_pConsole=pConsole;
	fillListView();
}

void KviChannelsJoinWindow::fillListView()
{
	m_pListView->clear();

	m_pListView->header()->hide();

	KviTalListViewItem * par = new KviTalListViewItem(m_pListView,__tr2qs("Recent Channels"));
	par->setOpen(true);
	KviTalListViewItem * chld;
	
	if(m_pConsole)
	{
	
		TQStringList* pList=g_pApp->getRecentChannels(m_pConsole->currentNetworkName());
		if(pList)
		{
			for(TQStringList::Iterator it = pList->begin(); it != pList->end(); ++it)
			{
				chld = new KviTalListViewItem(par,*it);
				chld->setPixmap(0,*(g_pIconManager->getSmallIcon(KVI_SMALLICON_CHANNEL)));
			}
		}
	}

	// FIXME: Registered channels go here!
	par = new KviTalListViewItem(m_pListView,__tr2qs("Registered Channels"));
	par->setOpen(true);

	KviPointerHashTable<const char *,KviRegisteredChannelList> * d = g_pRegisteredChannelDataBase->channelDict();
	if(d)
	{
		KviPointerHashTableIterator<const char *,KviRegisteredChannelList> it(*d);
		while(it.current())
		{
			chld = new KviTalListViewItem(par,it.currentKey());
			chld->setPixmap(0,*(g_pIconManager->getSmallIcon(KVI_SMALLICON_CHANNEL)));
			++it;
		}
	}


}

void KviChannelsJoinWindow::itemClicked(KviTalListViewItem * it) 
{
	if(!it)return;
	if(!it->parent())return;
	KviStr tmp = it->text(0);
	m_pChannelEdit->setText(tmp.ptr());
	enableJoin();
}

void KviChannelsJoinWindow::itemDoubleClicked(KviTalListViewItem * it) 
{
	if(!it)return;
	if(!it->parent())return;
	KviStr tmp = it->text(0);
	m_pChannelEdit->setText(tmp.ptr());
	enableJoin();
	joinClicked();
}


void KviChannelsJoinWindow::editTextChanged(const TQString &)
{
	enableJoin();
}

void KviChannelsJoinWindow::enableJoin()
{
	KviStr tmp = m_pChannelEdit->text();
	KviConsole * c = g_pApp->topmostConnectedConsole();
	if(c)
	{
		if(tmp.isEmpty())
			m_pJoinButton->setEnabled(false);
		else
			m_pJoinButton->setEnabled(true);
	} else {
		m_pListView->setEnabled(false);
		m_pGroupBox->setEnabled(false);
		m_pJoinButton->setEnabled(false);
	}
}

void KviChannelsJoinWindow::cancelClicked()
{
	delete this;
}

void KviChannelsJoinWindow::joinClicked()
{
	KviStr pass = m_pPass->text();
	KviStr tmp = m_pChannelEdit->text();

	if(tmp.isEmpty())return;

	KviStr command(KviStr::Format,"join %s %s",tmp.ptr(),pass.ptr());

	KviConsole * c = g_pApp->topmostConnectedConsole();
	if(!c)return; // no connection
	KviWindow * w = g_pActiveWindow;
	if(w->console() != c)w = c;
	KviKvsScript::run(command.ptr(),w);

	m_pChannelEdit->setText("");
	m_pPass->setText("");
}

/*
void KviChannelsJoinWindow::whoClicked()
{
	KviStr tmp = m_pChannelEdit->text();
	if(!tmp.isEmpty())doCmd("who", tmp.ptr());
}

void KviChannelsJoinWindow::namesClicked()
{
	KviStr tmp = m_pChannelEdit->text();
	//FIXME: I must be a nice guy and implement /names in the core...
	if(!tmp.isEmpty())doCmd("raw names", tmp.ptr());
}

void KviChannelsJoinWindow::itemDoubleClicked(KviTalListBoxItem * it)
{
	if (it == 0)return;
	KviStr tmp = it->text();
	doCmd("join", tmp.ptr());
//	if(KVI_OPTION_BOOL(KviOption_boolCloseChannelsJoinAfterJoin))
//		g_pApp->collectGarbage(this);
}
*/

void KviChannelsJoinWindow::editReturnPressed()
{
	joinClicked();
}	

void KviChannelsJoinWindow::closeEvent(TQCloseEvent *e)
{
	e->ignore();
	delete this;
}

#include "m_channelsjoinwindow.moc"