Prevent Quassel from crashing upon core dis- and reconnect and make the NickListWidgets
[quassel.git] / src / qtopia / nicklistwidget.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by the Quassel IRC Team                         *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #include "nicklistwidget.h"
22
23 #include "buffer.h"
24 #include "nickview.h"
25
26 NickListWidget::NickListWidget(QWidget *parent) : QDialog(parent) {
27   ui.setupUi(this);
28   setModal(true);
29   setStyleSheet("background-color: rgba(220, 220, 255, 40%); color: rgb(0, 0, 0); font-size: 5pt;");
30
31
32 }
33
34 NickListWidget::~NickListWidget() {
35
36
37
38 }
39
40 void NickListWidget::setBuffer(Buffer *buf) {
41   if(!buf) {
42     ui.stackedWidget->setCurrentWidget(ui.emptyPage);
43     return;
44   }
45   if(buf->bufferType() != Buffer::ChannelType) {
46     ui.stackedWidget->setCurrentWidget(ui.emptyPage);
47   } else {
48     if(nickViews.contains(buf)) {
49       ui.stackedWidget->setCurrentWidget(nickViews.value(buf));
50     } else {
51       NickView *view = new NickView(this);
52       view->setModel(buf->nickModel());
53       nickViews[buf] = view;
54       ui.stackedWidget->addWidget(view);
55       ui.stackedWidget->setCurrentWidget(view);
56       connect(buf, SIGNAL(destroyed(QObject *)), this, SLOT(bufferDestroyed(QObject *)));
57     }
58   }
59 }
60
61 void NickListWidget::reset() {
62   foreach(NickView *view, nickViews.values()) {
63     ui.stackedWidget->removeWidget(view);
64     view->deleteLater();
65   }
66   nickViews.clear();
67 }
68
69 void NickListWidget::bufferDestroyed(QObject *buf) {
70   if(nickViews.contains((Buffer *)buf)) {
71     NickView *view = nickViews.take((Buffer *)buf);
72     ui.stackedWidget->removeWidget(view);
73     view->deleteLater();
74   }
75 }
76