~ubuntu-branches/ubuntu/hoary/kvirc/hoary

« back to all changes in this revision

Viewing changes to src/kvirc/kvi_maskeditor.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Robin Verduijn
  • Date: 2004-12-14 15:32:19 UTC
  • mfrom: (0.2.1 upstream) (1.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20041214153219-fdink3gyp2s20b6g
Tags: 2:2.1.3.1-2
* Change Recommends on xmms to a Suggests.
* Rebuild against KDE 3.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// =============================================================================
 
2
//
 
3
//      --- kvi_maskeditor.cpp ---
 
4
//
 
5
//   This file is part of the KVIrc IRC client distribution
 
6
//   Copyright (C) 1999-2000 Szymon Stefanek (stefanek@tin.it)
 
7
//
 
8
//   This program is FREE software. You can redistribute it and/or
 
9
//   modify it under the terms of the GNU General Public License
 
10
//   as published by the Free Software Foundation; either version 2
 
11
//   of the License, or (at your opinion) any later version.
 
12
//
 
13
//   This program is distributed in the HOPE that it will be USEFUL,
 
14
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
16
//   See the GNU General Public License for more details.
 
17
//
 
18
//   You should have received a copy of the GNU General Public License
 
19
//   along with this program. If not, write to the Free Software Foundation,
 
20
//   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
21
//
 
22
// =============================================================================
 
23
 
 
24
#define _KVI_DEBUG_CHECK_RANGE_
 
25
#define _KVI_DEBUG_CLASS_NAME_ "KviMaskEditor"
 
26
 
 
27
#include <qlayout.h>
 
28
 
 
29
#include "kvi_banmask.h"
 
30
#include "kvi_label.h"
 
31
#include "kvi_listview.h"
 
32
#include "kvi_locale.h"
 
33
#include "kvi_maskeditor.h"
 
34
#include "kvi_pushbutton.h"
 
35
 
 
36
KviMaskEditor::KviMaskEditor(QWidget *parent)
 
37
        : QFrame(parent)
 
38
{
 
39
        setFrameStyle(QFrame::WinPanel | QFrame::Raised);
 
40
        setFocusPolicy(ClickFocus);
 
41
 
 
42
        QGridLayout *g = new QGridLayout(this, 5, 1, 2, 2);
 
43
 
 
44
        m_pLabel = new KviLabel("", this);
 
45
        g->addWidget(m_pLabel, 0, 0);
 
46
 
 
47
 
 
48
        m_pMaskBox = new KviListView(this);
 
49
        m_pMaskBox->setFocusPolicy(ClickFocus);
 
50
        m_pMaskBox->setFocusProxy(this);
 
51
        m_pMaskBox->addColumn(_CHAR_2_QSTRING(_i18n_(" - Mask - List - ")));
 
52
        m_pMaskBox->addColumn(_CHAR_2_QSTRING(_i18n_("Set by")));
 
53
        m_pMaskBox->addColumn(_CHAR_2_QSTRING(_i18n_("Set at")));
 
54
        m_pMaskBox->setMultiSelection(true);
 
55
        g->addWidget(m_pMaskBox, 1, 0);
 
56
 
 
57
        m_pRemoveMask  = new KviPushButton(_i18n_("&Remove"), this);
 
58
        m_pRemoveMask->setFocusPolicy(ClickFocus);
 
59
        m_pRemoveMask->setFocusProxy(this);
 
60
        connect(m_pRemoveMask, SIGNAL(clicked()), this, SLOT(removeMaskClicked()));
 
61
        g->addWidget(m_pRemoveMask, 2, 0);
 
62
 
 
63
        m_pCommit = new KviPushButton(_i18n_("&OK"), this);
 
64
        m_pCommit->setFocusPolicy(ClickFocus);
 
65
        m_pCommit->setFocusProxy(this);
 
66
        connect(m_pCommit, SIGNAL(clicked()), this, SLOT(commitChanges()));
 
67
        g->addWidget(m_pCommit, 3, 0);
 
68
 
 
69
        KviPushButton *b = new KviPushButton(_i18n_("&Cancel"), this);
 
70
        b->setFocusPolicy(ClickFocus);
 
71
        b->setFocusProxy(this);
 
72
        connect(b, SIGNAL(clicked()), this, SLOT(cancelClicked()));
 
73
        g->addWidget(b, 4, 0);
 
74
}
 
75
 
 
76
KviMaskEditor::~KviMaskEditor()
 
77
{
 
78
        // Nothing here
 
79
}
 
80
 
 
81
void KviMaskEditor::doEdit(
 
82
        QObject *receiver, const char *slot, QPtrList<KviBanMask> *maskList, const char *masksLabel, bool canCommit)
 
83
{
 
84
        disconnect(this, SIGNAL(masksEditCompleted(const char *)), 0, 0);
 
85
        connect(this, SIGNAL(masksEditCompleted(const char *)), receiver, slot);
 
86
        KviStr mLabel(KviStr::Format, "<b>%s List</b>", masksLabel);
 
87
        m_pLabel->setText(mLabel.ptr());
 
88
        setMasks(maskList, masksLabel);
 
89
        m_pCommit->setEnabled(canCommit);
 
90
        m_pRemoveMask->setEnabled(canCommit && (m_pMaskBox->childCount() > 0));
 
91
        m_szMasksRemoved = "";
 
92
        show();
 
93
        setFocus();
 
94
}
 
95
 
 
96
void KviMaskEditor::setMasks(QPtrList<KviBanMask> *maskList, const char *masksLabel)
 
97
{
 
98
        m_pMaskBox->clear();
 
99
        m_pMaskBox->setColumnText(0, _CHAR_2_QSTRING(masksLabel));
 
100
        KviListViewItem *i = 0;
 
101
        for( KviBanMask *b = maskList->first(); b; b = maskList->next() ) {
 
102
                i = new KviListViewItem(m_pMaskBox,
 
103
                        _CHAR_2_QSTRING(b->mask.ptr()), _CHAR_2_QSTRING(b->setBy.ptr()), _CHAR_2_QSTRING(b->setAt.ptr())
 
104
                );
 
105
        }
 
106
}
 
107
 
 
108
void KviMaskEditor::setCanCommit(bool bCanCommit)
 
109
{
 
110
        m_pCommit->setEnabled(bCanCommit);
 
111
        m_pRemoveMask->setEnabled(bCanCommit && (m_pMaskBox->childCount() > 0));
 
112
}
 
113
 
 
114
void KviMaskEditor::removeMaskClicked()
 
115
{
 
116
        KviListViewItem *it = m_pMaskBox->firstChild();
 
117
        while( it ) {
 
118
                if( it->isSelected() ) {
 
119
                        if( m_szMasksRemoved.hasData() )
 
120
                                m_szMasksRemoved += " ";
 
121
                        m_szMasksRemoved += it->text(0);
 
122
                        KviListViewItem *tmp = it;
 
123
                        it = it->nextSibling();
 
124
                        delete tmp;
 
125
                } else it = it->nextSibling();
 
126
        }
 
127
        m_pRemoveMask->setEnabled(m_pMaskBox->childCount() > 0);
 
128
}
 
129
 
 
130
void KviMaskEditor::commitChanges()
 
131
{
 
132
        emit masksEditCompleted(m_szMasksRemoved.ptr());
 
133
}
 
134
 
 
135
void KviMaskEditor::cancelClicked()
 
136
{
 
137
        emit masksEditCompleted("");
 
138
}
 
139
 
 
140
#include "m_kvi_maskeditor.moc"