summaryrefslogtreecommitdiffstats
path: root/src/svnfrontend/fronthelpers/propertylist.cpp
blob: 1b9a2d27eefc78a5d00a2acdebce8033e7022ee5 (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
/***************************************************************************
 *   Copyright (C) 2007 by Rajko Albrecht  ral@alwins-world.de             *
 *   http://tdesvn.alwins-world.de/                                        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) 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 "propertylist.h"
#include "propertyitem.h"

#include <klocale.h>
#include <kdebug.h>
#include <kmessagebox.h>


Propertylist::Propertylist(TQWidget *parent, const char *name)
    : KListView(parent, name),m_commitit(false)
{
    addColumn(i18n("Property"));
    addColumn(i18n("Value"));
    setShowSortIndicator(true);
    setAllColumnsShowFocus (true);
    setRootIsDecorated(false);
    setSortColumn(0);
    setAcceptDrops(false);
    connect(this,TQT_SIGNAL(itemRenamed(TQListViewItem*,const TQString&,int)),this,TQT_SLOT(slotItemRenamed(TQListViewItem*,const TQString&,int)));

    connect(this,TQT_SIGNAL(contextMenuRequested(TQListViewItem *, const TQPoint &, int)),this,
            TQT_SLOT(slotContextMenuRequested(TQListViewItem *, const TQPoint &, int)));
    //setFullWidth( TRUE );
}


Propertylist::~Propertylist()
{
}

void Propertylist::displayList(const svn::PathPropertiesMapListPtr&propList,bool editable,const TQString&aCur)
{
    viewport()->setUpdatesEnabled(false);
    clear();
    setItemsRenameable(editable);
    setRenameable(0,editable);
    setRenameable(1,editable);
    if (propList) {
        m_current = aCur;
        svn::PathPropertiesMapList::const_iterator lit;
        svn::PropertiesMap pmap;
        for (lit=propList->begin();lit!=propList->end();++lit) {
            pmap = (*lit).second;
            /* just want the first one */
            break;
        }
        svn::PropertiesMap::const_iterator pit;
        for (pit=pmap.begin();pit!=pmap.end();++pit) {
            PropertyListViewItem * ki = new PropertyListViewItem(this,
                    pit.key(),
                    pit.data());
        }
    }
    viewport()->setUpdatesEnabled(true);
    viewport()->tqrepaint();
}

void Propertylist::clear()
{
    KListView::clear();
}

/*!
    \fn PropertiesDlg::slotItemRenamed(TQListViewItem*item,const TQString & str,int col )
 */
void Propertylist::slotItemRenamed(TQListViewItem*_item,const TQString & text,int col )
{
    if (!_item || _item->rtti()!=PropertyListViewItem::_RTTI_) return;
    PropertyListViewItem*item = static_cast<PropertyListViewItem*> (_item);

    kdDebug()<<"Text: "<< text << " in col "<<col << endl;

    if (text.isEmpty()&&col == 0) {
        // fresh added
        if (item->currentName().isEmpty()) {
            delete item;
        } else {
            item->setText(0,item->currentName());
        }
        return;
    }
    if (PropertyListViewItem::protected_Property(item->text(0)) ||
        PropertyListViewItem::protected_Property(item->currentName())) {
        KMessageBox::error(this,i18n("This property may not set by users.\nRejecting it."),i18n("Protected property"));
        item->setText(0,item->currentName());
        item->setText(1,item->currentValue());
        return;
    }
    if (checkExisting(item->text(0),item)) {
        KMessageBox::error(this,i18n("A property with that name exists.\nRejecting it."),i18n("Double property"));
        item->setText(0,item->currentName());
        item->setText(1,item->currentValue());
        return;
    }

    if (col==0) {
        item->checkName();
    } else {
        item->checkValue();
    }
    if (commitchanges() && item->different()) {
        svn::PropertiesMap pm;
        TQValueList<TQString> dels;
        pm[item->currentName()]=item->currentValue();
        if (item->currentName()!=item->startName()){
            dels.push_back(item->startName());
        }
        emit sigSetProperty(pm,dels,m_current);
    }
}

bool Propertylist::checkExisting(const TQString&aName,TQListViewItem*it)
{
    if (!it) {
        return findItem(aName,0)!=0;
    }
    TQListViewItemIterator iter(this);
    while ( iter.current() ) {
        if ( iter.current()==it) {
            ++iter;
            continue;
        }
        if (iter.current()->text(0)==aName) {
            return true;
        }
        ++iter;
    }
    return false;
}

void Propertylist::addCallback(TQObject*ob)
{
    if (ob) {
        connect(this,TQT_SIGNAL(sigSetProperty(const svn::PropertiesMap&,const TQValueList<TQString>&,const TQString&)),
                ob,TQT_SLOT(slotChangeProperties(const svn::PropertiesMap&,const TQValueList<TQString>&,const TQString&)));
    }
}

/*!
    \fn Propertylist::slotContextMenuRequested(TQListViewItem *, const TQPoint &, int)
 */
void Propertylist::slotContextMenuRequested(TQListViewItem *, const TQPoint &, int)
{
    /// @todo implement me
}

#include "propertylist.moc"