~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to buildtools/custommakefiles/selectnewfilesdialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2007 by Andreas Pakulat                                 *
3
 
 *   apaku@gmx.de                                                          *
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) any later version.                                   *
9
 
 *                                                                         *
10
 
 ***************************************************************************/
11
 
 
12
 
 
13
 
#include "selectnewfilesdialog.h"
14
 
 
15
 
#include <qlistview.h>
16
 
#include <klistview.h>
17
 
#include <qheader.h>
18
 
#include <qstringlist.h>
19
 
#include <klocale.h>
20
 
#include <kdebug.h>
21
 
#include "selectnewfilesdialogbase.h"
22
 
 
23
 
SelectNewFilesDialog::SelectNewFilesDialog( QStringList paths, QWidget* parent, const char* name )
24
 
        : KDialogBase( parent, name, true, i18n("Add newly created files to project"), KDialogBase::Ok|KDialogBase::Cancel )
25
 
{
26
 
    m_widget = new SelectNewFilesDialogBase(this);
27
 
    m_widget->fileView->header()->hide();
28
 
    m_widget->fileView->addColumn(i18n("Path") );
29
 
    for( QStringList::const_iterator it = paths.begin(); it != paths.end(); ++it)
30
 
    {
31
 
        addPath(0, *it);
32
 
    }
33
 
    setMainWidget( m_widget );
34
 
    resize( 300,400 );
35
 
}
36
 
 
37
 
SelectNewFilesDialog::~SelectNewFilesDialog()
38
 
{}
39
 
 
40
 
void SelectNewFilesDialog::slotCancel()
41
 
{
42
 
    excludePaths.clear();
43
 
    includePaths.clear();
44
 
    KDialogBase::slotCancel();
45
 
}
46
 
 
47
 
void SelectNewFilesDialog::checkItem( QCheckListItem* item, const QString& curpath )
48
 
{
49
 
    if( !item )
50
 
        return;
51
 
 
52
 
    QString path = curpath + item->text();
53
 
    if( item->state() != QCheckListItem::Off )
54
 
        includePaths << path;
55
 
    else
56
 
        excludePaths << path;
57
 
    if( item->firstChild() )
58
 
    {
59
 
        checkItem( static_cast<QCheckListItem*>(item->firstChild()), path+"/" );
60
 
    }
61
 
    if( item->nextSibling() )
62
 
    {
63
 
        checkItem( static_cast<QCheckListItem*>(item->nextSibling()), curpath );
64
 
    }
65
 
}
66
 
 
67
 
void SelectNewFilesDialog::slotOk()
68
 
{
69
 
    QCheckListItem* item = static_cast<QCheckListItem*> (m_widget->fileView->firstChild());
70
 
    checkItem( item, "" );
71
 
    kdDebug(9025) << "Inc List:" << includePaths << endl;
72
 
    kdDebug(9025) << "Exc List:" << excludePaths << endl;
73
 
    KDialogBase::slotOk();
74
 
}
75
 
 
76
 
void SelectNewFilesDialog::addPath( QCheckListItem* item, const QString& path )
77
 
{
78
 
    if( path.isEmpty() )
79
 
        return;
80
 
 
81
 
    QStringList parts = QStringList::split("/", path );
82
 
    QString name = parts.first();
83
 
    parts.pop_front();
84
 
    QCheckListItem* i = createItem( item, name, parts.size() );
85
 
    i->setState( QCheckListItem::On );
86
 
    i->setTristate( true );
87
 
    addPath(i, parts.join("/") );
88
 
}
89
 
 
90
 
QCheckListItem* SelectNewFilesDialog::createItem( QCheckListItem* parent, const QString& name, int count )
91
 
{
92
 
    QCheckListItem::Type t = QCheckListItem::CheckBox;
93
 
    if( count > 0 )
94
 
        t = QCheckListItem::CheckBoxController;
95
 
 
96
 
    if( parent == 0 )
97
 
    {
98
 
        QListViewItem* item = m_widget->fileView->firstChild();
99
 
        while( item )
100
 
        {
101
 
            if( item->text( 0 ) == name )
102
 
                return static_cast<QCheckListItem*>(item);
103
 
            item = item->nextSibling();
104
 
        }
105
 
        return new QCheckListItem( m_widget->fileView, name, t );
106
 
    }else
107
 
    {
108
 
        QListViewItem* item = parent->firstChild();
109
 
        while( item )
110
 
        {
111
 
            if( item->text( 0 ) == name )
112
 
                return static_cast<QCheckListItem*>(item);
113
 
            item = item->nextSibling();
114
 
        }
115
 
        return new QCheckListItem( parent, name, t );
116
 
    }
117
 
}
118
 
 
119
 
QStringList SelectNewFilesDialog::excludedPaths() const
120
 
{
121
 
    return excludePaths;
122
 
}
123
 
 
124
 
QStringList SelectNewFilesDialog::includedPaths() const
125
 
{
126
 
    return includePaths;
127
 
}
128
 
 
129
 
#include "selectnewfilesdialog.moc"
130
 
 
131
 
// kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on